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