Debian Codegraph @

gcc/testsuite/gdc.test/fail_compilation/test21518.d

raw
1 /*
2 https://issues.dlang.org/show_bug.cgi?id=21518
3 TEST_OUTPUT:
4 ---
5 fail_compilation/test21518.d(19): Error: cannot implicitly convert expression `[dg]` of type `const(void delegate() pure nothrow @nogc @system)[]` to `void delegate() @safe[]`
6 fail_compilation/test21518.d(23): Error: cannot implicitly convert expression `[dg]` of type `const(void delegate() pure nothrow @nogc @system)[]` to `const(void delegate() @safe)[]`
7 fail_compilation/test21518.d(28): Error: cannot implicitly convert expression `sysA` of type `const(void delegate() @system)[]` to `const(void delegate() @safe)[]`
8 fail_compilation/test21518.d(31): Error: cannot implicitly convert expression `sysA` of type `const(void delegate() @system)[]` to `const(void delegate() @safe)`
9 fail_compilation/test21518.d(32): Error: cannot implicitly convert expression `dg` of type `const(void delegate() pure nothrow @nogc @system)` to `const(void delegate() @safe)`
10 ---
11 */
12
13 void delegates()
14 {
15 const dg = delegate() @system { int* p; int x; p = &x; };
16 // pragma(msg, typeof(dg)); // const(void delegate() pure nothrow @nogc @system)
17
18 // Correctly fails
19 void delegate() @safe[] arg2 = [ dg ];
20 void delegate() @system[] arg3 = [ dg ]; // But doesnt break this
21
22 // Previously ignored
23 const(void delegate() @safe)[] arg = [ dg ];
24 // pragma(msg, typeof(arg)); // const(void delegate() @safe)[]
25
26 // Also for variables, not only array literals
27 const(void delegate() @system)[] sysA = [ dg ];
28 const(void delegate() @safe)[] safeA = sysA;
29
30 // Original bug report:
31 func(sysA);
32 func(dg);
33 }
34
35 void func(const void delegate() @safe [] paramDGs...) @safe
36 {
37 if (paramDGs.length > 0) paramDGs[0]();
38 }