Debian Codegraph @

src/test/01-Basic/219-func-call-refs.ck

raw
1 // test reference count
2 // related: https://github.com/ccrma/chuck/issues/374
3
4 // class
5 class Foo
6 {
7 5 => int x;
8 }
9
10 // another class
11 class Bar
12 {
13 // instance of Foo
14 Foo foo;
15 // get it
16 fun Foo getFoo() { return foo; }
17 // take as argument
18 fun void setFoo( Foo f )
19 {
20 // should be 3
21 <<< Machine.refcount(f) >>>;
22 }
23 }
24
25 // instance of Bar
26 Bar bar;
27 // should be 1
28 <<< Machine.refcount(bar.foo) >>>;
29
30 // verify no missing release from getFoo()
31 bar.getFoo() @=> Foo @ foo;
32 //should be 2
33 <<< Machine.refcount(bar.foo) >>>;
34
35 // multi-exp stmt
36 bar.getFoo(), bar.getFoo().x, bar.getFoo();
37 // should be 2
38 <<< Machine.refcount(bar.foo) >>>;
39
40 // call a function
41 bar.setFoo( bar.foo );