| 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 semantics of the ?. operator when it appears on the LHS of an | 5 // Verify semantics of the ?. operator when it appears on the LHS of an |
| 6 // assignment. | 6 // assignment. |
| 7 | 7 |
| 8 // SharedOptions=--enable-null-aware-operators | |
| 9 | |
| 10 import "package:expect/expect.dart"; | 8 import "package:expect/expect.dart"; |
| 11 import "conditional_access_helper.dart" as h; | 9 import "conditional_access_helper.dart" as h; |
| 12 | 10 |
| 13 bad() { | 11 bad() { |
| 14 Expect.fail('Should not be executed'); | 12 Expect.fail('Should not be executed'); |
| 15 } | 13 } |
| 16 | 14 |
| 17 noMethod(e) => e is NoSuchMethodError; | 15 noMethod(e) => e is NoSuchMethodError; |
| 18 | 16 |
| 19 class B {} | 17 class B {} |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 84 Expect.throws(() => h.C?.staticField = null, noMethod); /// 17: static type wa
rning | 82 Expect.throws(() => h.C?.staticField = null, noMethod); /// 17: static type wa
rning |
| 85 Expect.throws(() => h.C?.staticField += null, noMethod); /// 18: static type w
arning | 83 Expect.throws(() => h.C?.staticField += null, noMethod); /// 18: static type w
arning |
| 86 Expect.throws(() => h.C?.staticField ??= null, noMethod); /// 19: static type
warning | 84 Expect.throws(() => h.C?.staticField ??= null, noMethod); /// 19: static type
warning |
| 87 | 85 |
| 88 // Nor can it be used to assign to toplevel properties in libraries imported | 86 // Nor can it be used to assign to toplevel properties in libraries imported |
| 89 // via prefix. | 87 // via prefix. |
| 90 h?.topLevelVar = null; /// 20: compile-time error | 88 h?.topLevelVar = null; /// 20: compile-time error |
| 91 h?.topLevelVar += null; /// 21: compile-time error | 89 h?.topLevelVar += null; /// 21: compile-time error |
| 92 h?.topLevelVar ??= null; /// 22: compile-time error | 90 h?.topLevelVar ??= null; /// 22: compile-time error |
| 93 } | 91 } |
| OLD | NEW |