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 // Evaluation of an if-null expresion e of the form e1 ?? e2 is equivalent to | 5 // Evaluation of an if-null expresion e of the form e1 ?? e2 is equivalent to |
6 // the evaluation of the expression ((x) => x == null ? e2 : x)(e1). The | 6 // the evaluation of the expression ((x) => x == null ? e2 : x)(e1). The |
7 // static type of e is the least upper bound of the static type of e1 and the | 7 // static type of e is the least upper bound of the static type of e1 and the |
8 // static type of e2. | 8 // static type of e2. |
9 | 9 |
10 import "package:expect/expect.dart"; | 10 import "package:expect/expect.dart"; |
(...skipping 16 matching lines...) Expand all Loading... |
27 B nullB() => null; | 27 B nullB() => null; |
28 C nullC() => null; | 28 C nullC() => null; |
29 | 29 |
30 noMethod(e) => e is NoSuchMethodError; | 30 noMethod(e) => e is NoSuchMethodError; |
31 | 31 |
32 main() { | 32 main() { |
33 // Make sure the "none" test fails if "??" is not implemented. This makes | 33 // Make sure the "none" test fails if "??" is not implemented. This makes |
34 // status files easier to maintain. | 34 // status files easier to maintain. |
35 var _ = null ?? null; | 35 var _ = null ?? null; |
36 | 36 |
37 Expect.equals(1, 1 ?? 2); /// 01: ok | 37 Expect.equals(1, 1 ?? 2); //# 01: ok |
38 Expect.equals(1, 1 ?? null); /// 02: ok | 38 Expect.equals(1, 1 ?? null); //# 02: ok |
39 Expect.equals(2, null ?? 2); /// 03: ok | 39 Expect.equals(2, null ?? 2); //# 03: ok |
40 Expect.equals(null, null ?? null); /// 04: ok | 40 Expect.equals(null, null ?? null); //# 04: ok |
41 Expect.equals('B', (new B('B') ?? new C('C')).a); /// 05: ok | 41 Expect.equals('B', (new B('B') ?? new C('C')).a); //# 05: ok |
42 Expect.equals('B', (new B('B') ?? new C('C')).b); /// 06: static type warning | 42 Expect.equals('B', (new B('B') ?? new C('C')).b); //# 06: static type warning |
43 Expect.throws(() => (new B('B') ?? new C('C')).c, noMethod); /// 07: static ty
pe warning | 43 Expect.throws(() => (new B('B') ?? new C('C')).c, noMethod); //# 07: static ty
pe warning |
44 Expect.equals('B', (new B('B') ?? nullC()).a); /// 08: ok | 44 Expect.equals('B', (new B('B') ?? nullC()).a); //# 08: ok |
45 Expect.equals('B', (new B('B') ?? nullC()).b); /// 09: static type warning | 45 Expect.equals('B', (new B('B') ?? nullC()).b); //# 09: static type warning |
46 Expect.throws(() => (new B('B') ?? nullC()).c, noMethod); /// 10: static type
warning | 46 Expect.throws(() => (new B('B') ?? nullC()).c, noMethod); //# 10: static type
warning |
47 Expect.equals('C', (nullB() ?? new C('C')).a); /// 11: ok | 47 Expect.equals('C', (nullB() ?? new C('C')).a); //# 11: ok |
48 Expect.throws(() => (nullB() ?? new C('C')).b, noMethod); /// 12: static type
warning | 48 Expect.throws(() => (nullB() ?? new C('C')).b, noMethod); //# 12: static type
warning |
49 Expect.equals('C', (nullB() ?? new C('C')).c); /// 13: static type warning | 49 Expect.equals('C', (nullB() ?? new C('C')).c); //# 13: static type warning |
50 Expect.throws(() => (nullB() ?? nullC()).a, noMethod); /// 14: ok | 50 Expect.throws(() => (nullB() ?? nullC()).a, noMethod); //# 14: ok |
51 Expect.throws(() => (nullB() ?? nullC()).b, noMethod); /// 15: static type war
ning | 51 Expect.throws(() => (nullB() ?? nullC()).b, noMethod); //# 15: static type war
ning |
52 Expect.throws(() => (nullB() ?? nullC()).c, noMethod); /// 16: static type war
ning | 52 Expect.throws(() => (nullB() ?? nullC()).c, noMethod); //# 16: static type war
ning |
53 } | 53 } |
OLD | NEW |