| 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 import "package:expect/expect.dart"; | |
| 6 | |
| 7 foo() => 123; | |
| 8 | |
| 9 void testShadowingScope1() { | |
| 10 var foo = foo(); | |
| 11 Expect.equals(123, foo); | |
| 12 } | |
| 13 | |
| 14 void testShadowingScope2() { | |
| 15 { | |
| 16 var foo = foo() + 444; | |
| 17 Expect.equals(567, foo); | |
| 18 } | |
| 19 Expect.equals(123, foo()); | |
| 20 } | |
| 21 | |
| 22 void testShadowingCapture1() { | |
| 23 var f; | |
| 24 { | |
| 25 var foo = 888; | |
| 26 f = () => foo; | |
| 27 } | |
| 28 var foo = -888; | |
| 29 Expect.equals(888, f()); | |
| 30 } | |
| 31 | |
| 32 void testShadowingCapture2() { | |
| 33 var f = null; | |
| 34 // this one uses a reentrant block | |
| 35 for (int i = 0; i < 2; i++) { | |
| 36 var foo = i + 888; | |
| 37 if (f == null) f = () => foo; | |
| 38 } | |
| 39 var foo = -888; | |
| 40 | |
| 41 // this could break if it doesn't bind the right "foo" | |
| 42 Expect.equals(888, f()); | |
| 43 } | |
| 44 | |
| 45 class BlockScopeTest1 { | |
| 46 void testShadowingInstanceVar() { | |
| 47 if (true) { | |
| 48 var foo = foo() + 444; | |
| 49 Expect.equals(1221, foo); | |
| 50 } | |
| 51 Expect.equals(777, foo()); | |
| 52 } | |
| 53 static void testShadowingStatic() { | |
| 54 if (true) { | |
| 55 var bar = bar() + 444; | |
| 56 Expect.equals(1221, bar); | |
| 57 } | |
| 58 Expect.equals(777, bar()); | |
| 59 } | |
| 60 | |
| 61 foo() => 777; | |
| 62 static bar() => 777; | |
| 63 } | |
| 64 | |
| 65 main() { | |
| 66 testShadowingScope1(); | |
| 67 testShadowingScope2(); | |
| 68 testShadowingCapture1(); | |
| 69 testShadowingCapture2(); | |
| 70 new BlockScopeTest1().testShadowingInstanceVar(); | |
| 71 BlockScopeTest1.testShadowingStatic(); | |
| 72 } | |
| OLD | NEW |