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 | 6 |
7 // Interpolation effect analysis test. | 7 // Interpolation effect analysis test. |
8 | 8 |
9 get never => new DateTime.now().millisecondsSinceEpoch == 0; | 9 get never => new DateTime.now().millisecondsSinceEpoch == 0; |
10 | 10 |
11 class A { | 11 class A { |
12 int a = 0; | 12 int a = 0; |
13 toString() { ++a; return 'A'; } | 13 toString() { |
| 14 ++a; |
| 15 return 'A'; |
| 16 } |
14 } | 17 } |
15 | 18 |
16 // Many interpolations to make function too big to inline. | 19 // Many interpolations to make function too big to inline. |
17 // Summary for [fmt] must include effects from toString(). | 20 // Summary for [fmt] must include effects from toString(). |
18 fmt(x) => '$x$x$x$x$x$x$x$x$x$x$x$x$x$x$x$x$x$x$x$x$x$x$x$x$x$x$x$x$x$x'; | 21 fmt(x) => '$x$x$x$x$x$x$x$x$x$x$x$x$x$x$x$x$x$x$x$x$x$x$x$x$x$x$x$x$x$x'; |
19 | 22 |
20 test(a) { | 23 test(a) { |
21 if (a == null) return; | 24 if (a == null) return; |
22 if (never) a.a += 1; | 25 if (never) a.a += 1; |
23 var b = a.a; // field load | 26 var b = a.a; // field load |
24 var c = fmt(a); // field modified through implicit call to toString() | 27 var c = fmt(a); // field modified through implicit call to toString() |
25 var d = a.a; // field re-load | 28 var d = a.a; // field re-load |
26 Expect.equals('A 0 AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA 30', '$a $b $c $d'); | 29 Expect.equals('A 0 AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA 30', '$a $b $c $d'); |
27 | 30 |
28 // Extra use of [fmt] to prevent inlining on basis of single reference. | 31 // Extra use of [fmt] to prevent inlining on basis of single reference. |
29 Expect.equals('', fmt('')); | 32 Expect.equals('', fmt('')); |
30 } | 33 } |
31 | 34 |
32 main() { | 35 main() { |
33 test(null); | 36 test(null); |
34 test(new A()); | 37 test(new A()); |
35 } | 38 } |
OLD | NEW |