| OLD | NEW |
| 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, 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 // SharedOptions=--enable-null-aware-operators | 5 // SharedOptions=--enable-null-aware-operators |
| 6 // VMOptions=--optimization_counter_threshold=5 | 6 // VMOptions=--optimization_counter_threshold=5 |
| 7 // | 7 // |
| 8 // Basic null-aware operator test that invokes the optimizing compiler. | 8 // Basic null-aware operator test that invokes the optimizing compiler. |
| 9 | 9 |
| 10 import "package:expect/expect.dart"; | 10 import "package:expect/expect.dart"; |
| (...skipping 18 matching lines...) Expand all Loading... |
| 29 Expect.equals(null, getNull()?.anything(bomb())); | 29 Expect.equals(null, getNull()?.anything(bomb())); |
| 30 Expect.equals(1, d?.m(1)); | 30 Expect.equals(1, d?.m(1)); |
| 31 Expect.equals("C", C?.toString()); | 31 Expect.equals("C", C?.toString()); |
| 32 | 32 |
| 33 Expect.equals(1, new C(1)?.f); | 33 Expect.equals(1, new C(1)?.f); |
| 34 Expect.equals(null, c?.v); | 34 Expect.equals(null, c?.v); |
| 35 Expect.equals(10, c ?? 10); | 35 Expect.equals(10, c ?? 10); |
| 36 Expect.equals(d, d ?? bomb()); | 36 Expect.equals(d, d ?? bomb()); |
| 37 | 37 |
| 38 var e; | 38 var e; |
| 39 // The assginment to e is not executed since d != null. | 39 // The assignment to e is not executed since d != null. |
| 40 d ??= e ??= new C(100); | 40 d ??= e ??= new C(100); |
| 41 Expect.equals(null, e); | 41 Expect.equals(null, e); |
| 42 e ??= new C(100); | 42 e ??= new C(100); |
| 43 Expect.equals(100, e?.f); | 43 Expect.equals(100, e?.f); |
| 44 e?.f ??= 200; | 44 e?.f ??= 200; |
| 45 Expect.equals(100, e?.f); | 45 Expect.equals(100, e?.f); |
| 46 | 46 |
| 47 e.f = null; | 47 e.f = null; |
| 48 e?.f ??= 200; | 48 e?.f ??= 200; |
| 49 Expect.equals(200, e?.f); | 49 Expect.equals(200, e?.f); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 63 c?.v; | 63 c?.v; |
| 64 c?.m(bomb()); | 64 c?.m(bomb()); |
| 65 } | 65 } |
| 66 | 66 |
| 67 main() { | 67 main() { |
| 68 for (int i = 0; i < 10; i++) { | 68 for (int i = 0; i < 10; i++) { |
| 69 test(); | 69 test(); |
| 70 test2(); | 70 test2(); |
| 71 } | 71 } |
| 72 } | 72 } |
| OLD | NEW |