OLD | NEW |
| (Empty) |
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | |
2 // for details. All rights reserved. Use of this source code is governed by a | |
3 // BSD-style license that can be found in the LICENSE file. | |
4 | |
5 foo() => 123; | |
6 | |
7 void testShadowingScope1() { | |
8 var foo = foo(); | |
9 Expect.equals(123, foo); | |
10 } | |
11 | |
12 void testShadowingScope2() { | |
13 { | |
14 var foo = foo() + 444; | |
15 Expect.equals(567, foo); | |
16 } | |
17 Expect.equals(123, foo()); | |
18 } | |
19 | |
20 void testShadowingCapture1() { | |
21 var f; | |
22 { | |
23 var foo = 888; | |
24 f = () => foo; | |
25 } | |
26 var foo = -888; | |
27 Expect.equals(888, f()); | |
28 } | |
29 | |
30 void testShadowingCapture2() { | |
31 var f = null; | |
32 // this one uses a reentrent block | |
33 for (int i = 0; i < 2; i++) { | |
34 var foo = i + 888; | |
35 if (f == null) f = () => foo; | |
36 } while(false); | |
37 var foo = -888; | |
38 | |
39 // this could break if it doesn't bind the right "foo" | |
40 Expect.equals(888, f()); | |
41 } | |
42 | |
43 class BlockScopeTest1 { | |
44 void testShadowingInstanceVar() { | |
45 if (true) { | |
46 var foo = foo() + 444; | |
47 Expect.equals(1221, foo); | |
48 } | |
49 Expect.equals(777, foo()); | |
50 } | |
51 static void testShadowingStatic() { | |
52 if (true) { | |
53 var bar = bar() + 444; | |
54 Expect.equals(1221, bar); | |
55 } | |
56 Expect.equals(777, bar()); | |
57 } | |
58 | |
59 foo() => 777; | |
60 static bar() => 777; | |
61 } | |
62 | |
63 main() { | |
64 testShadowingScope1(); | |
65 testShadowingScope2(); | |
66 testShadowingCapture1(); | |
67 testShadowingCapture2(); | |
68 new BlockScopeTest1().testShadowingInstanceVar(); | |
69 BlockScopeTest1.testShadowingStatic(); | |
70 } | |
OLD | NEW |