blob: ff532aea220aba820883d88a99ef8146a5d19842 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
/*
TEST_OUTPUT:
---
fail_compilation/test15306.d(15): Error: `immutable` delegate `test15306.main.__dgliteral2` cannot access mutable data `i`
fail_compilation/test15306.d(19): Error: `shared` delegate `test15306.main.__dgliteral5` cannot access non-shared data `p`
---
*/
// https://issues.dlang.org/show_bug.cgi?id=15306
void main()
{
// immutable cannot access mutable
int i = 42;
auto dg1 = delegate void() immutable { auto inner = i; };
// shared cannot access unshared
int* p = &i;
auto dg2 = delegate int() shared { return *p; };
assert(dg2() == i);
// unshared can access shared
shared j = 43;
shared int* q = &j;
auto dg3 = delegate int() { return *q; };
assert(dg2() == j);
}
|