| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2016, 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 'expect.dart'; | |
| 6 | |
| 7 // Test that the context depth is correct in the presence of control flow, | |
| 8 // specifically branching and joining in the presence of break. The | |
| 9 // implementation uses the context depth after the else block of an if/then/else | |
| 10 // as the context depth at the join point. This test has an extra context | |
| 11 // allocated in the (untaken) else branch so it tests that compiling the | |
| 12 // (untaken) break properly tracks the context depth. | |
| 13 | |
| 14 test(list) { | |
| 15 // The loops force creation of a new context, otherwise context allocated | |
| 16 // variables might be hoisted to an outer context. | |
| 17 do { | |
| 18 if (list.length > 1) { | |
| 19 do { | |
| 20 var sum = 0; | |
| 21 addem() { | |
| 22 for (var x in list) sum += x; | |
| 23 } | |
| 24 addem(); | |
| 25 Expect.isTrue(sum == 15); | |
| 26 L: if (sum != 15) { | |
| 27 // Unreachable. | |
| 28 do { | |
| 29 var product = 1; | |
| 30 multiplyem() { | |
| 31 for (var x in list) product *= n; | |
| 32 } | |
| 33 multiplyem(); | |
| 34 Expect.isTrue(false); | |
| 35 break L; | |
| 36 } while (false); | |
| 37 } | |
| 38 } while (false); | |
| 39 } | |
| 40 } while (false); | |
| 41 Expect.isTrue(list.length == 5); | |
| 42 } | |
| 43 | |
| 44 | |
| 45 main() { | |
| 46 test([1, 2, 3, 4, 5]); | |
| 47 } | |
| OLD | NEW |