| 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 is used to invoke a method. | 5 // Verify semantics of the ?. operator when it is used to invoke a method. |
| 6 | 6 |
| 7 // SharedOptions=--enable-null-aware-operators | |
| 8 | |
| 9 import "package:expect/expect.dart"; | 7 import "package:expect/expect.dart"; |
| 10 import "conditional_access_helper.dart" as h; | 8 import "conditional_access_helper.dart" as h; |
| 11 | 9 |
| 12 bad() { | 10 bad() { |
| 13 Expect.fail('Should not be executed'); | 11 Expect.fail('Should not be executed'); |
| 14 } | 12 } |
| 15 | 13 |
| 16 noMethod(e) => e is NoSuchMethodError; | 14 noMethod(e) => e is NoSuchMethodError; |
| 17 | 15 |
| 18 class B {} | 16 class B {} |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 52 Expect.throws(() => h.C?.staticMethod(), noMethod); /// 10: static type warnin
g | 50 Expect.throws(() => h.C?.staticMethod(), noMethod); /// 10: static type warnin
g |
| 53 | 51 |
| 54 // Nor can it be used to access toplevel functions in libraries imported via | 52 // Nor can it be used to access toplevel functions in libraries imported via |
| 55 // prefix. | 53 // prefix. |
| 56 h?.topLevelFunction(); /// 11: compile-time error | 54 h?.topLevelFunction(); /// 11: compile-time error |
| 57 | 55 |
| 58 // However, '?.' can be used to access the toString method on the class Type. | 56 // However, '?.' can be used to access the toString method on the class Type. |
| 59 Expect.equals(C?.toString(), (C).toString()); /// 12: ok | 57 Expect.equals(C?.toString(), (C).toString()); /// 12: ok |
| 60 Expect.equals(h.C?.toString(), (h.C).toString()); /// 13: ok | 58 Expect.equals(h.C?.toString(), (h.C).toString()); /// 13: ok |
| 61 } | 59 } |
| OLD | NEW |