Debian Codegraph @

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

raw
1 /*
2 REQUIRED_ARGS: -preview=dip1000
3 TEST_OUTPUT:
4 ---
5 fail_compilation/test23073.d(28): Error: assigning scope variable `c` to non-scope parameter `c` calling `assignNext` is not allowed in a `@safe` function
6 fail_compilation/test23073.d(22): which is not `scope` because of `c.next = c`
7 ---
8 */
9
10 // https://issues.dlang.org/show_bug.cgi?id=23073
11 // scope inference from pure doesn't consider self-assignment
12
13 @safe:
14
15 class C
16 {
17 C next;
18 }
19
20 void assignNext(C c) pure nothrow @nogc
21 {
22 c.next = c;
23 }
24
25 C escape() @nogc
26 {
27 scope C c = new C();
28 assignNext(c);
29 return c.next;
30 }
31
32 void main()
33 {
34 C dangling = escape();
35 }