| OLD | NEW |
| (Empty) | |
| 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 |
| 3 // BSD-style license that can be found in the LICENSE file. |
| 4 |
| 5 // SharedOptions=--enable-null-aware-operators |
| 6 import "package:expect/expect.dart"; |
| 7 |
| 8 @NoInline() @AssumeDynamic() |
| 9 confuse(x) => x; |
| 10 |
| 11 main(args) { |
| 12 var x = new A(); |
| 13 var y; |
| 14 |
| 15 // Checks that inference doesn't incorrectly treat this as a normal |
| 16 // assignment (where only B is a possible value after the assignment). |
| 17 var c = x ??= new B(); |
| 18 var z = x; |
| 19 Expect.equals('a', x.m()); |
| 20 Expect.equals('a', z.m()); |
| 21 Expect.equals('a', c.m()); |
| 22 if (confuse(true)) y = x; |
| 23 Expect.equals('a', y.m()); |
| 24 |
| 25 // Similar test, within fields. |
| 26 new C(); |
| 27 new D(); |
| 28 } |
| 29 |
| 30 class A { m() => 'a'; } |
| 31 class B { m() => 'b'; } |
| 32 |
| 33 class C { |
| 34 var y; |
| 35 C() { |
| 36 y = new A(); |
| 37 var c = y ??= new B(); |
| 38 Expect.equals('a', y.m()); |
| 39 Expect.equals('a', c.m()); |
| 40 } |
| 41 } |
| 42 |
| 43 class D { |
| 44 var y; |
| 45 D() { |
| 46 this.y = new A(); |
| 47 var c = this.y ??= new B(); |
| 48 Expect.equals('a', y.m()); |
| 49 Expect.equals('a', c.m()); |
| 50 } |
| 51 } |
| OLD | NEW |