| 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 // Verify that the static type of a ??= b is the least upper bound of the | 5 // Verify that the static type of a ??= b is the least upper bound of the |
| 6 // static types of a and b. | 6 // static types of a and b. |
| 7 | 7 |
| 8 // SharedOptions=--enable-null-aware-operators | |
| 9 | |
| 10 import "package:expect/expect.dart"; | 8 import "package:expect/expect.dart"; |
| 11 | 9 |
| 12 // Determine whether the VM is running in checked mode. | 10 // Determine whether the VM is running in checked mode. |
| 13 bool get checkedMode { | 11 bool get checkedMode { |
| 14 try { | 12 try { |
| 15 var x = 'foo'; | 13 var x = 'foo'; |
| 16 int y = x; | 14 int y = x; |
| 17 return false; | 15 return false; |
| 18 } catch (_) { | 16 } catch (_) { |
| 19 return true; | 17 return true; |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 167 (new ClassWithInstanceGetters()?.a ??= new B()).b; /// 39: static type warning | 165 (new ClassWithInstanceGetters()?.a ??= new B()).b; /// 39: static type warning |
| 168 if (!checkedMode) { | 166 if (!checkedMode) { |
| 169 (new ClassWithInstanceGetters()?.b ??= new A()).a; /// 40: ok | 167 (new ClassWithInstanceGetters()?.b ??= new A()).a; /// 40: ok |
| 170 Expect.throws(() => (new ClassWithInstanceGetters()?.b ??= new A()).b, noMet
hod); /// 41: static type warning | 168 Expect.throws(() => (new ClassWithInstanceGetters()?.b ??= new A()).b, noMet
hod); /// 41: static type warning |
| 171 | 169 |
| 172 // Exactly the same static warnings that would be caused by e1.v ??= e2 are | 170 // Exactly the same static warnings that would be caused by e1.v ??= e2 are |
| 173 // also generated in the case of e1?.v ??= e2. | 171 // also generated in the case of e1?.v ??= e2. |
| 174 new ClassWithInstanceGetters()?.b ??= new C(); /// 42: static type warning | 172 new ClassWithInstanceGetters()?.b ??= new C(); /// 42: static type warning |
| 175 } | 173 } |
| 176 } | 174 } |
| OLD | NEW |