| OLD | NEW |
| 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 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 | 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. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 import 'package:expect/expect.dart'; | 5 import 'package:expect/expect.dart'; |
| 6 | 6 |
| 7 // Test that the context depth is correct in the presence of control flow, | 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 | 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 | 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 | 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 | 11 // allocated in the (untaken) else branch so it tests that compiling the |
| 12 // (untaken) break properly tracks the context depth. | 12 // (untaken) break properly tracks the context depth. |
| 13 | 13 |
| 14 test(list) { | 14 test(list) { |
| 15 // The loops force creation of a new context, otherwise context allocated | 15 // The loops force creation of a new context, otherwise context allocated |
| 16 // variables might be hoisted to an outer context. | 16 // variables might be hoisted to an outer context. |
| 17 do { | 17 do { |
| 18 if (list.length > 1) { | 18 if (list.length > 1) { |
| 19 do { | 19 do { |
| 20 var sum = 0; | 20 var sum = 0; |
| 21 addem() { | 21 addem() { |
| 22 for (var x in list) sum += x; | 22 for (var x in list) sum += x; |
| 23 } | 23 } |
| 24 |
| 24 addem(); | 25 addem(); |
| 25 Expect.isTrue(sum == 15); | 26 Expect.isTrue(sum == 15); |
| 26 L: if (sum != 15) { | 27 L: |
| 28 if (sum != 15) { |
| 27 // Unreachable. | 29 // Unreachable. |
| 28 do { | 30 do { |
| 29 var product = 1; | 31 var product = 1; |
| 30 multiplyem() { | 32 multiplyem() { |
| 31 for (var x in list) product *= x; | 33 for (var x in list) product *= x; |
| 32 } | 34 } |
| 35 |
| 33 multiplyem(); | 36 multiplyem(); |
| 34 Expect.isTrue(false); | 37 Expect.isTrue(false); |
| 35 break L; | 38 break L; |
| 36 } while (false); | 39 } while (false); |
| 37 } | 40 } |
| 38 } while (false); | 41 } while (false); |
| 39 } | 42 } |
| 40 } while (false); | 43 } while (false); |
| 41 Expect.isTrue(list.length == 5); | 44 Expect.isTrue(list.length == 5); |
| 42 } | 45 } |
| 43 | 46 |
| 44 | |
| 45 main() { | 47 main() { |
| 46 test([1, 2, 3, 4, 5]); | 48 test([1, 2, 3, 4, 5]); |
| 47 } | 49 } |
| OLD | NEW |