| 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 does not appear on the LHS of an | 5 // Verify semantics of the ?. operator when it does not appear 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 noMethod(e) => e is NoSuchMethodError; | 11 noMethod(e) => e is NoSuchMethodError; |
| 14 | 12 |
| 15 class B {} | 13 class B {} |
| 16 | 14 |
| 17 class C extends B { | 15 class C extends B { |
| 18 int v; | 16 int v; |
| 19 C(this.v); | 17 C(this.v); |
| (...skipping 26 matching lines...) Expand all Loading... |
| 46 Expect.throws(() => h.C?.staticField, noMethod); /// 08: static type warning | 44 Expect.throws(() => h.C?.staticField, noMethod); /// 08: static type warning |
| 47 | 45 |
| 48 // Nor can it be used to access toplevel properties in libraries imported via | 46 // Nor can it be used to access toplevel properties in libraries imported via |
| 49 // prefix. | 47 // prefix. |
| 50 var x = h?.topLevelVar; /// 09: compile-time error | 48 var x = h?.topLevelVar; /// 09: compile-time error |
| 51 | 49 |
| 52 // However, '?.' can be used to access the hashCode getter on the class Type. | 50 // However, '?.' can be used to access the hashCode getter on the class Type. |
| 53 Expect.equals(C?.hashCode, (C).hashCode); /// 10: ok | 51 Expect.equals(C?.hashCode, (C).hashCode); /// 10: ok |
| 54 Expect.equals(h.C?.hashCode, (h.C).hashCode); /// 11: ok | 52 Expect.equals(h.C?.hashCode, (h.C).hashCode); /// 11: ok |
| 55 } | 53 } |
| OLD | NEW |