| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 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 | 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 import "compiler_annotations.dart"; | 6 import "compiler_annotations.dart"; |
| 7 | 7 |
| 8 var a = [null]; | 8 var a = [null]; |
| 9 | 9 |
| 10 class A { | 10 class A { |
| 11 var foo; | 11 var foo; |
| 12 var bar; | 12 var bar; |
| 13 | 13 |
| 14 @DontInline | 14 @DontInline() |
| 15 A() { | 15 A() { |
| 16 // Currently defeat inlining by using a closure. | 16 // Currently defeat inlining by using a closure. |
| 17 bar = () => 42; | 17 bar = () => 42; |
| 18 foo = 42; | 18 foo = 42; |
| 19 foo = a[0]; | 19 foo = a[0]; |
| 20 } | 20 } |
| 21 } | 21 } |
| 22 | 22 |
| 23 class B { | 23 class B { |
| 24 var foo; | 24 var foo; |
| 25 var bar; | 25 var bar; |
| 26 | 26 |
| 27 @DontInline | 27 @DontInline() |
| 28 B() { | 28 B() { |
| 29 // Currently defeat inlining by using a closure. | 29 // Currently defeat inlining by using a closure. |
| 30 bar = () => 42; | 30 bar = () => 42; |
| 31 foo = 42; | 31 foo = 42; |
| 32 foo = a[0]; | 32 foo = a[0]; |
| 33 if (false) foo = 42; | 33 if (false) foo = 42; |
| 34 } | 34 } |
| 35 } | 35 } |
| 36 | 36 |
| 37 main() { | 37 main() { |
| 38 // Surround the call to [bar] by allocations of [A] and [B] to | 38 // Surround the call to [bar] by allocations of [A] and [B] to |
| 39 // ensure their constructors get analyzed first. | 39 // ensure their constructors get analyzed first. |
| 40 new A(); | 40 new A(); |
| 41 new B(); | 41 new B(); |
| 42 bar(); | 42 bar(); |
| 43 new A(); | 43 new A(); |
| 44 new B(); | 44 new B(); |
| 45 } | 45 } |
| 46 | 46 |
| 47 @DontInline | 47 @DontInline() |
| 48 bar() { | 48 bar() { |
| 49 // Currently defeat inlining by using a closure. | 49 // Currently defeat inlining by using a closure. |
| 50 Expect.throws(() => new A().foo + 42, (e) => e is NoSuchMethodError); | 50 Expect.throws(() => new A().foo + 42, (e) => e is NoSuchMethodError); |
| 51 Expect.throws(() => new B().foo + 42, (e) => e is NoSuchMethodError); | 51 Expect.throws(() => new B().foo + 42, (e) => e is NoSuchMethodError); |
| 52 } | 52 } |
| OLD | NEW |