| 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 that '??' binds tighter than '?:' and less tightly than '||'. | 5 // Verify that '??' binds tighter than '?:' and less tightly than '||'. |
| 6 | 6 |
| 7 import "package:expect/expect.dart"; | 7 import "package:expect/expect.dart"; |
| 8 | 8 |
| 9 assertionError(e) => e is AssertionError; | 9 assertionError(e) => e is AssertionError; |
| 10 | 10 |
| (...skipping 30 matching lines...) Expand all Loading... |
| 41 // type warning if b doesn't have type bool. An incorrect parse of | 41 // type warning if b doesn't have type bool. An incorrect parse of |
| 42 // "(a ?? b) || c" would allow b to have any type provided that a is bool. | 42 // "(a ?? b) || c" would allow b to have any type provided that a is bool. |
| 43 Expect.equals(false, false ?? 1 || true); /// 06: static type warning | 43 Expect.equals(false, false ?? 1 || true); /// 06: static type warning |
| 44 | 44 |
| 45 // "a || b ?? c" should parse as "(a || b) ?? c", therefore it is a static | 45 // "a || b ?? c" should parse as "(a || b) ?? c", therefore it is a static |
| 46 // type warning if b doesn't have type bool. An incorrect parse of | 46 // type warning if b doesn't have type bool. An incorrect parse of |
| 47 // "a || (b ?? c)" would allow b to have any type provided that c is bool. | 47 // "a || (b ?? c)" would allow b to have any type provided that c is bool. |
| 48 if (checkedMode) { | 48 if (checkedMode) { |
| 49 Expect.throws(() => false || 1 ?? true, assertionError); /// 07: static type
warning | 49 Expect.throws(() => false || 1 ?? true, assertionError); /// 07: static type
warning |
| 50 } else { | 50 } else { |
| 51 Expect.equals(false, false || 1 ?? true); /// 07: continued | 51 Expect.equals(false, false || 1 ?? true); // /// 07: continued |
| 52 } | 52 } |
| 53 | 53 |
| 54 if (checkedMode) { | 54 if (checkedMode) { |
| 55 // An incorrect parse of "a || (b ?? c)" would result in no checked-mode | 55 // An incorrect parse of "a || (b ?? c)" would result in no checked-mode |
| 56 // error. | 56 // error. |
| 57 Expect.throws(() => false || null ?? true, assertionError); /// 08: ok | 57 Expect.throws(() => false || null ?? true, assertionError); /// 08: ok |
| 58 } else { | 58 } else { |
| 59 // An incorrect parse of "a || (b ?? c)" would result in c being evaluated. | 59 // An incorrect parse of "a || (b ?? c)" would result in c being evaluated. |
| 60 int i = 0; /// 08: continue
d | 60 int i = 0; // /// 08: contin
ued |
| 61 Expect.equals(false, false || null ?? i++ == 0); /// 08: continue
d | 61 Expect.equals(false, false || null ?? i++ == 0); // /// 08: contin
ued |
| 62 Expect.equals(0, i); /// 08: continue
d | 62 Expect.equals(0, i); // /// 08: contin
ued |
| 63 } | 63 } |
| 64 } | 64 } |
| OLD | NEW |