Debian Codegraph @

src/test/01-Basic/220-dangel-ref-loop.ck

raw
1 // verify func-call returning objects is properly refcounted
2 // as part or the stmt's object release mechanism | 1.5.1.7
3
4 // a class
5 class Foo
6 {
7 5 => int x;
8 }
9
10 // a file-global instance
11 Foo foo;
12 // a function that returns foo
13 fun Foo bar() { return foo; }
14
15 // since bar() returns an object every iteration, verify the
16 // stmt reference count is correct
17 while( bar().x )
18 {
19 // do this a few times
20 bar().x--;
21 }
22
23 // check
24 if( Machine.refcount(foo) == 1 ) <<< "success" >>>;