| 1 |
// this test value lookup when there are multiple variables of the same |
| 2 |
// name declared in different situations |
| 3 |
// 1) local scope: test2()'s `8000 int foo` |
| 4 |
// 2) up scope within class def; second print of `foo` in test2() |
| 5 |
// 3) inherited member (2000 A.foo) |
| 6 |
// 3) up scope beyond class def (global-scope 4000 int foo) |
| 7 |
|
| 8 |
class A |
| 9 |
{ |
| 10 |
// member of A |
| 11 |
2000 => int foo; |
| 12 |
} |
| 13 |
|
| 14 |
// global-scope |
| 15 |
4000 => int foo; |
| 16 |
|
| 17 |
// subclass of A |
| 18 |
class B extends A |
| 19 |
{ |
| 20 |
{ |
| 21 |
{ |
| 22 |
// this should resolve to A.foo over the global-scope foo |
| 23 |
<<< "b", foo >>>; |
| 24 |
} |
| 25 |
} |
| 26 |
|
| 27 |
fun void test1() |
| 28 |
{ |
| 29 |
{ |
| 30 |
// this should resolve to A.foo over the global-scope foo |
| 31 |
<<< "b", foo >>>; |
| 32 |
} |
| 33 |
} |
| 34 |
|
| 35 |
fun void test2() |
| 36 |
{ |
| 37 |
// local variable |
| 38 |
8000 => int foo; |
| 39 |
|
| 40 |
// this should resolve to the local variable foo |
| 41 |
<<< "b", foo >>>; |
| 42 |
{ |
| 43 |
// this should resolve to the local variable foo |
| 44 |
<<< "b", foo >>>; |
| 45 |
} |
| 46 |
} |
| 47 |
} |
| 48 |
|
| 49 |
B b; |
| 50 |
|
| 51 |
// don't use comparison here (b.foo) but instead |
| 52 |
// observe output to verify value in specific contexts |
| 53 |
b.test1(); |
| 54 |
b.test2(); |