Debian Codegraph @

src/test/01-Basic/267-static-init-more.ck

raw
1 // static variable initialization
2 // some extended tests for static variable initialization
3 // #2024-static-init
4
5 // a class
6 class Bar
7 {
8 // a non-static function
9 fun int bar() { return 1; }
10 }
11
12 // another class
13 public class Foo
14 {
15 // a static function
16 fun static int foo() { return 2; }
17
18 // static Bar object
19 static Bar myBar;
20
21 // OK: using static object myBar to initialize a static var
22 myBar.bar() => static int myFoo1;
23 // OK: explicitly using Foo.myBar.bar() to initialize a static var
24 Foo.myBar.bar() => static int myFoo2;
25 // OK: although uses `this` AND bar() is not static, myBar is static
26 this.myBar.bar() => static int myFoo3;
27 // OK: although uses `this`, the function foo() is static
28 this.foo() => static int myFoo4;
29 }
30
31 // should print 1 1 1 2
32 <<< Foo.myFoo1, Foo.myFoo2, Foo.myFoo3, Foo.myFoo4 >>>;