Debian Codegraph @

src/test/01-Basic/281-object-conditional.ck

raw
1 class Foo {}
2
3 Foo foo;
4 Foo@ null_foo;
5 SinOsc@ null_osc;
6 SinOsc osc;
7
8 fun void checkNull(Object@ o, string name) {
9 if (o) <<< name, "is NOT null" >>>;
10 // if (o) <<< name, "is NOT null" >>>;
11 else <<< name, "is null" >>>;
12 }
13
14 checkNull(foo, "foo");
15 checkNull(null_foo, "null_foo");
16 checkNull(osc, "osc");
17 checkNull(null_osc, "null_osc");
18
19 fun Object@ getNullObj() { return null_osc; }
20 fun Object@ getObj() { return foo; }
21
22 if (getObj()) <<< "getObj is not null" >>>;
23 if (!getNullObj()) <<< "getNullObj is null" >>>;
24
25 if (osc) <<< "if (object)" >>>;
26 if (foo) <<< "if (user)" >>>;
27 if (!null_foo) <<< "!User" >>>;
28 if (!null_osc) <<< "!Object" >>>;
29
30 if (null_foo || foo) <<< "User || User" >>>;
31 if (osc || null_osc) <<< "Object || Object" >>>;
32 if (osc || null_foo) <<< "Object || User" >>>;
33 if (foo || null_osc) <<< "User || Object" >>>;
34
35 if (foo && foo) <<< "User && User" >>>;
36 if (osc && osc) <<< "Object && Object" >>>;
37 if (foo && osc) <<< "User && Object" >>>;
38 if (osc && foo) <<< "User && Object" >>>;
39
40 while (null_foo) {}
41 while (null_osc) {}
42 while (osc) { break; }
43 while (foo) { break; }