| OLD | NEW |
| (Empty) | |
| 1 // Copyright (c) 2013, 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 // Regression test for dart2js. There was a bug in the variable |
| 6 // allocator when a pure (side-effect free) instruction stand |
| 7 // in-between an inlined `if` and its inlined expression. |
| 8 |
| 9 import "package:expect/expect.dart"; |
| 10 |
| 11 var topLevel; |
| 12 |
| 13 // Make [foo] an inlineable expression with a return type check. |
| 14 Function foo(c) { |
| 15 // Use [c] twice to make sure it is stored in a local. |
| 16 return (c is Function ? null : c); |
| 17 } |
| 18 |
| 19 bar() { |
| 20 var b = new Object(); |
| 21 f() { |
| 22 // Inside a closure, locals that escape are stored in a closure |
| 23 // class. By using [b] in both branches, the optimizers will move |
| 24 // the fetching of [b] before the `if`. This puts the fetching |
| 25 // instruction in between the `if` and the expression of the `if`. |
| 26 // This instruction being pure, the variable allocator was dealing |
| 27 // with it in a special way. |
| 28 // |
| 29 // Because the expression in the `if` is being recognized by the |
| 30 // optimizers as being also a JavaScript expression, we do not |
| 31 // allocate a name for it. But some expressions that it uses still |
| 32 // can have a name, and our variable allocator did not handle live |
| 33 // variables due to the inlining of the ternary expression in [foo]. |
| 34 if (foo(topLevel) == null) { |
| 35 return b.toString(); |
| 36 } else { |
| 37 return b.hashCode; |
| 38 } |
| 39 } |
| 40 return f(); |
| 41 } |
| 42 |
| 43 main() { |
| 44 // Make sure the inferrer does not get an exact type for [topLevel]. |
| 45 topLevel = new Object(); |
| 46 topLevel = main; |
| 47 var res = bar(); |
| 48 Expect.isTrue(res is String); |
| 49 } |
| OLD | NEW |