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 that used to generate wrong code for | |
6 // it. The bug happened in the SSA type propagation. | |
7 | |
8 class A { | |
9 next() => new B(); | |
10 doIt() => null; | |
11 bool get isEmpty => false; | |
12 foo() => 42; | |
13 bar() => 54; | |
14 } | |
15 | |
16 bool entered = false; | |
17 | |
18 class B extends A { | |
19 foo() => 54; | |
20 doIt() => new A(); | |
21 bool get isEmpty => true; | |
22 bar() => entered = true; | |
23 } | |
24 | |
25 // (1) At initialization phase of the type propagation, [a] would be | |
26 // marked as [exact A]. | |
27 // (2) Will make the loop phi [b] typed [null, exact A]. | |
28 // (3) Will create a [HTypeKnown] [exact A] for [b]. | |
29 // (4) Will create a [HTypeKnown] [exact A] for [b] and update users | |
30 // of [b] to use this [HTypeKnown] instead. | |
31 // (5) [a] will be updated to [subclass A]. | |
32 // (6) Will change the [HTypeKnown] of [b] from [exact A] to [subclass A]. | |
33 // (7) Receiver is [subclass A] and it will refine it to | |
34 // [subclass A]. We used to wrongly assume there was | |
35 // no need to update the [HTypeKnown] created in (3). | |
36 // (8) Consider that bar is called on an [exact A] (the [HTypeKnown] | |
37 // created in (3)) and remove the call because it does not have | |
38 // any side effects. | |
39 | |
40 main() { | |
41 var a = new A(); | |
42 for (var i in [42]) { | |
43 a = a.next(); | |
44 } | |
45 | |
46 // (1, 5) | |
47 | |
48 var b = a; | |
49 while (b.isEmpty) { | |
50 // (4, 6) | |
51 b.foo(); // (3, 7) | |
52 b.bar(); // (8) | |
53 b = b.doIt(); // (2) | |
54 } | |
55 | |
56 if (!entered) throw 'Test failed'; | |
57 } | |
OLD | NEW |