| 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 | 8 // SharedOptions=--enable-null-aware-operators |
| 9 | 9 |
| 10 import "package:expect/expect.dart"; | 10 import "package:expect/expect.dart"; |
| (...skipping 29 matching lines...) Expand all Loading... |
| 40 // generated in the case of e1?.id. | 40 // generated in the case of e1?.id. |
| 41 Expect.equals(null, nullC()?.bad); /// 05: static type warning | 41 Expect.equals(null, nullC()?.bad); /// 05: static type warning |
| 42 { B b = new C(1); Expect.equals(1, b?.v); } /// 06: static type warning | 42 { B b = new C(1); Expect.equals(1, b?.v); } /// 06: static type warning |
| 43 | 43 |
| 44 // Consequently, '?.' cannot be used to access static properties of classes. | 44 // Consequently, '?.' cannot be used to access static properties of classes. |
| 45 Expect.throws(() => C?.staticField, noMethod); /// 07: static type warning | 45 Expect.throws(() => C?.staticField, noMethod); /// 07: static type warning |
| 46 Expect.throws(() => h.C?.staticField, noMethod); /// 08: static type warning | 46 Expect.throws(() => h.C?.staticField, noMethod); /// 08: static type warning |
| 47 | 47 |
| 48 // Nor can it be used to access toplevel properties in libraries imported via | 48 // Nor can it be used to access toplevel properties in libraries imported via |
| 49 // prefix. | 49 // prefix. |
| 50 Expect.throws(() => h?.topLevelVar, noMethod); /// 09: static type warning | 50 var x = h?.topLevelVar; /// 09: compile-time error |
| 51 | 51 |
| 52 // However, '?.' can be used to access the hashCode getter on the class Type. | 52 // However, '?.' can be used to access the hashCode getter on the class Type. |
| 53 Expect.equals(C?.hashCode, (C).hashCode); /// 10: ok | 53 Expect.equals(C?.hashCode, (C).hashCode); /// 10: ok |
| 54 Expect.equals(h.C?.hashCode, (h.C).hashCode); /// 11: ok | 54 Expect.equals(h.C?.hashCode, (h.C).hashCode); /// 11: ok |
| 55 } | 55 } |
| OLD | NEW |