| 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, including order of operations, by | 5 // Verify semantics of the ??= operator, including order of operations, by |
| 6 // keeping track of the operations performed. | 6 // keeping track of the operations performed. |
| 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 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 163 // v ??= e is equivalent to ((x) => x == null ? v = e : x)(v) | 163 // v ??= e is equivalent to ((x) => x == null ? v = e : x)(v) |
| 164 xGetValue = 1; check(1, () => x ??= bad(), ['x']); /// 07: ok | 164 xGetValue = 1; check(1, () => x ??= bad(), ['x']); /// 07: ok |
| 165 yGetValue = 1; check(1, () => x ??= y, ['x', 'y', 'x=1']); /// 08: ok | 165 yGetValue = 1; check(1, () => x ??= y, ['x', 'y', 'x=1']); /// 08: ok |
| 166 h.xGetValue = 1; check(1, () => h.x ??= bad(), ['h.x']); /// 09: ok | 166 h.xGetValue = 1; check(1, () => h.x ??= bad(), ['h.x']); /// 09: ok |
| 167 yGetValue = 1; check(1, () => h.x ??= y, ['h.x', 'y', 'h.x=1']); /// 10: ok | 167 yGetValue = 1; check(1, () => h.x ??= y, ['h.x', 'y', 'h.x=1']); /// 10: ok |
| 168 { var l = 1; check(1, () => l ??= bad(), []); } /// 11: ok | 168 { var l = 1; check(1, () => l ??= bad(), []); } /// 11: ok |
| 169 { var l; yGetValue = 1; check(1, () => l ??= y, ['y']); Expect.equals(1, l); }
/// 12: ok | 169 { var l; yGetValue = 1; check(1, () => l ??= y, ['y']); Expect.equals(1, l); }
/// 12: ok |
| 170 { final l = 1; check(1, () => l ??= bad(), []); } /// 13: static type warning | 170 { final l = 1; check(1, () => l ??= bad(), []); } /// 13: static type warning |
| 171 { final l = null; yGetValue = 1; checkThrows(noMethod, () => l ??= y, ['y']);
} /// 14: static type warning | 171 { final l = null; yGetValue = 1; checkThrows(noMethod, () => l ??= y, ['y']);
} /// 14: static type warning |
| 172 check(C, () => C ??= bad(), []); /// 15: static type warning | 172 check(C, () => C ??= bad(), []); /// 15: static type warning |
| 173 h ??= null; /// 29: compile-time error |
| 174 h[0] ??= null; /// 30: compile-time error |
| 173 | 175 |
| 174 // C.v ??= e is equivalent to ((x) => x == null ? C.v = e : x)(C.v) | 176 // C.v ??= e is equivalent to ((x) => x == null ? C.v = e : x)(C.v) |
| 175 C.xGetValue = 1; check(1, () => C.x ??= bad(), ['C.x']); /// 16: ok | 177 C.xGetValue = 1; check(1, () => C.x ??= bad(), ['C.x']); /// 16: ok |
| 176 yGetValue = 1; check(1, () => C.x ??= y, ['C.x', 'y', 'C.x=1']); /// 17: ok | 178 yGetValue = 1; check(1, () => C.x ??= y, ['C.x', 'y', 'C.x=1']); /// 17: ok |
| 177 h.C.xGetValue = 1; check(1, () => h.C.x ??= bad(), ['h.C.x']); /// 18: ok | 179 h.C.xGetValue = 1; check(1, () => h.C.x ??= bad(), ['h.C.x']); /// 18: ok |
| 178 yGetValue = 1; check(1, () => h.C.x ??= y, ['h.C.x', 'y', 'h.C.x=1']); /// 19:
ok | 180 yGetValue = 1; check(1, () => h.C.x ??= y, ['h.C.x', 'y', 'h.C.x=1']); /// 19:
ok |
| 179 | 181 |
| 180 // e1.v ??= e2 is equivalent to | 182 // e1.v ??= e2 is equivalent to |
| 181 // ((x) => ((y) => y == null ? x.v = e2 : y)(x.v))(e1) | 183 // ((x) => ((y) => y == null ? x.v = e2 : y)(x.v))(e1) |
| 182 xGetValue = new C('x'); xGetValue.vGetValue = 1; /// 20: ok | 184 xGetValue = new C('x'); xGetValue.vGetValue = 1; /// 20: ok |
| (...skipping 12 matching lines...) Expand all Loading... |
| 195 xGetValue = new C('x'); yGetValue = 1; zGetValue = 2; /// 25: ok | 197 xGetValue = new C('x'); yGetValue = 1; zGetValue = 2; /// 25: ok |
| 196 check(2, () => x[y] ??= z, ['x', 'y', 'x[1]', 'z', 'x[1]=2']); /// 25: continu
ed | 198 check(2, () => x[y] ??= z, ['x', 'y', 'x[1]', 'z', 'x[1]=2']); /// 25: continu
ed |
| 197 | 199 |
| 198 // e1?.v ??= e2 is equivalent to ((x) => x == null ? null : x.v ??= e2)(e1). | 200 // e1?.v ??= e2 is equivalent to ((x) => x == null ? null : x.v ??= e2)(e1). |
| 199 check(null, () => x?.v ??= bad(), ['x']); /// 26: ok | 201 check(null, () => x?.v ??= bad(), ['x']); /// 26: ok |
| 200 xGetValue = new C('x'); xGetValue.vGetValue = 1; /// 27: ok | 202 xGetValue = new C('x'); xGetValue.vGetValue = 1; /// 27: ok |
| 201 check(1, () => x?.v ??= bad(), ['x', 'x.v']); /// 27: continued | 203 check(1, () => x?.v ??= bad(), ['x', 'x.v']); /// 27: continued |
| 202 xGetValue = new C('x'); yGetValue = 1; /// 28: ok | 204 xGetValue = new C('x'); yGetValue = 1; /// 28: ok |
| 203 check(1, () => x?.v ??= y, ['x', 'x.v', 'y', 'x.v=1']); /// 28: continued | 205 check(1, () => x?.v ??= y, ['x', 'x.v', 'y', 'x.v=1']); /// 28: continued |
| 204 } | 206 } |
| OLD | NEW |