| 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 appears in a postincrement or | 5 // Verify semantics of the ?. operator when it appears in a postincrement or |
| 6 // preincrement expression (or a postdecrement or predecrement expression). | 6 // preincrement expression (or a postdecrement or predecrement expression). |
| 7 | 7 |
| 8 import "package:expect/expect.dart"; | 8 import "package:expect/expect.dart"; |
| 9 import "conditional_access_helper.dart" as h; | 9 import "conditional_access_helper.dart" as h; |
| 10 | 10 |
| (...skipping 23 matching lines...) Expand all Loading... |
| 34 class I extends G implements H {} | 34 class I extends G implements H {} |
| 35 | 35 |
| 36 C nullC() => null; | 36 C nullC() => null; |
| 37 | 37 |
| 38 main() { | 38 main() { |
| 39 // Make sure the "none" test fails if assignment to "?." is not implemented. | 39 // Make sure the "none" test fails if assignment to "?." is not implemented. |
| 40 // This makes status files easier to maintain. | 40 // This makes status files easier to maintain. |
| 41 nullC()?.v = 1; | 41 nullC()?.v = 1; |
| 42 | 42 |
| 43 // e1?.v++ is equivalent to ((x) => x == null ? null : x.v++)(e1). | 43 // e1?.v++ is equivalent to ((x) => x == null ? null : x.v++)(e1). |
| 44 Expect.equals(null, nullC()?.v++); /// 01: ok | 44 Expect.equals(null, nullC()?.v++); //# 01: ok |
| 45 { C c = new C(1); Expect.equals(1, c?.v++); Expect.equals(2, c.v); } /// 02: o
k | 45 { C c = new C(1); Expect.equals(1, c?.v++); Expect.equals(2, c.v); } //# 02: o
k |
| 46 | 46 |
| 47 // C?.v++ is equivalent to C.v++. | 47 // C?.v++ is equivalent to C.v++. |
| 48 { C.staticInt = 1; Expect.equals(1, C?.staticInt++); Expect.equals(2, C.static
Int); } /// 17: ok | 48 { C.staticInt = 1; Expect.equals(1, C?.staticInt++); Expect.equals(2, C.static
Int); } //# 17: ok |
| 49 { h.C.staticInt = 1; Expect.equals(1, h.C?.staticInt++); Expect.equals(2, h.C.
staticInt); } /// 18: ok | 49 { h.C.staticInt = 1; Expect.equals(1, h.C?.staticInt++); Expect.equals(2, h.C.
staticInt); } //# 18: ok |
| 50 | 50 |
| 51 // The static type of e1?.v++ is the same as the static type of e1.v. | 51 // The static type of e1?.v++ is the same as the static type of e1.v. |
| 52 { E e1 = new E(); D d = new D(e1); E e2 = d?.v++; Expect.identical(e1, e2); }
/// 03: ok | 52 { E e1 = new E(); D d = new D(e1); E e2 = d?.v++; Expect.identical(e1, e2); }
//# 03: ok |
| 53 { G g = new G(); D d = new D(g); F f = d?.v++; Expect.identical(f, g); } /// 0
4: static type warning | 53 { G g = new G(); D d = new D(g); F f = d?.v++; Expect.identical(f, g); } //# 0
4: static type warning |
| 54 { E e1 = new E(); D.staticE = e1; E e2 = D?.staticE++; Expect.identical(e1, e2
); } /// 19: ok | 54 { E e1 = new E(); D.staticE = e1; E e2 = D?.staticE++; Expect.identical(e1, e2
); } //# 19: ok |
| 55 { h.E e1 = new h.E(); h.D.staticE = e1; h.E e2 = h.D?.staticE++; Expect.identi
cal(e1, e2); } /// 20: ok | 55 { h.E e1 = new h.E(); h.D.staticE = e1; h.E e2 = h.D?.staticE++; Expect.identi
cal(e1, e2); } //# 20: ok |
| 56 { G g = new G(); D.staticE = g; F f = D?.staticE++; Expect.identical(f, g); }
/// 21: static type warning | 56 { G g = new G(); D.staticE = g; F f = D?.staticE++; Expect.identical(f, g); }
//# 21: static type warning |
| 57 { h.G g = new h.G(); h.D.staticE = g; h.F f = h.D?.staticE++; Expect.identical
(f, g); } /// 22: static type warning | 57 { h.G g = new h.G(); h.D.staticE = g; h.F f = h.D?.staticE++; Expect.identical
(f, g); } //# 22: static type warning |
| 58 | 58 |
| 59 // e1?.v-- is equivalent to ((x) => x == null ? null : x.v--)(e1). | 59 // e1?.v-- is equivalent to ((x) => x == null ? null : x.v--)(e1). |
| 60 Expect.equals(null, nullC()?.v--); /// 05: ok | 60 Expect.equals(null, nullC()?.v--); //# 05: ok |
| 61 { C c = new C(1); Expect.equals(1, c?.v--); Expect.equals(0, c.v); } /// 06: o
k | 61 { C c = new C(1); Expect.equals(1, c?.v--); Expect.equals(0, c.v); } //# 06: o
k |
| 62 | 62 |
| 63 // C?.v-- is equivalent to C.v--. | 63 // C?.v-- is equivalent to C.v--. |
| 64 { C.staticInt = 1; Expect.equals(1, C?.staticInt--); Expect.equals(0, C.static
Int); } /// 23: ok | 64 { C.staticInt = 1; Expect.equals(1, C?.staticInt--); Expect.equals(0, C.static
Int); } //# 23: ok |
| 65 { h.C.staticInt = 1; Expect.equals(1, h.C?.staticInt--); Expect.equals(0, h.C.
staticInt); } /// 24: ok | 65 { h.C.staticInt = 1; Expect.equals(1, h.C?.staticInt--); Expect.equals(0, h.C.
staticInt); } //# 24: ok |
| 66 | 66 |
| 67 // The static type of e1?.v-- is the same as the static type of e1.v. | 67 // The static type of e1?.v-- is the same as the static type of e1.v. |
| 68 { E e1 = new E(); D d = new D(e1); E e2 = d?.v--; Expect.identical(e1, e2); }
/// 07: ok | 68 { E e1 = new E(); D d = new D(e1); E e2 = d?.v--; Expect.identical(e1, e2); }
//# 07: ok |
| 69 { G g = new G(); D d = new D(g); F f = d?.v--; Expect.identical(f, g); } /// 0
8: static type warning | 69 { G g = new G(); D d = new D(g); F f = d?.v--; Expect.identical(f, g); } //# 0
8: static type warning |
| 70 { E e1 = new E(); D.staticE = e1; E e2 = D?.staticE--; Expect.identical(e1, e2
); } /// 25: ok | 70 { E e1 = new E(); D.staticE = e1; E e2 = D?.staticE--; Expect.identical(e1, e2
); } //# 25: ok |
| 71 { h.E e1 = new h.E(); h.D.staticE = e1; h.E e2 = h.D?.staticE--; Expect.identi
cal(e1, e2); } /// 26: ok | 71 { h.E e1 = new h.E(); h.D.staticE = e1; h.E e2 = h.D?.staticE--; Expect.identi
cal(e1, e2); } //# 26: ok |
| 72 { G g = new G(); D.staticE = g; F f = D?.staticE--; Expect.identical(f, g); }
/// 27: static type warning | 72 { G g = new G(); D.staticE = g; F f = D?.staticE--; Expect.identical(f, g); }
//# 27: static type warning |
| 73 { h.G g = new h.G(); h.D.staticE = g; h.F f = h.D?.staticE--; Expect.identical
(f, g); } /// 28: static type warning | 73 { h.G g = new h.G(); h.D.staticE = g; h.F f = h.D?.staticE--; Expect.identical
(f, g); } //# 28: static type warning |
| 74 | 74 |
| 75 // ++e1?.v is equivalent to e1?.v += 1. | 75 // ++e1?.v is equivalent to e1?.v += 1. |
| 76 Expect.equals(null, ++nullC()?.v); /// 09: ok | 76 Expect.equals(null, ++nullC()?.v); //# 09: ok |
| 77 { C c = new C(1); Expect.equals(2, ++c?.v); Expect.equals(2, c.v); } /// 10: o
k | 77 { C c = new C(1); Expect.equals(2, ++c?.v); Expect.equals(2, c.v); } //# 10: o
k |
| 78 | 78 |
| 79 // ++C?.v is equivalent to C?.v += 1. | 79 // ++C?.v is equivalent to C?.v += 1. |
| 80 { C.staticInt = 1; Expect.equals(2, ++C?.staticInt); Expect.equals(2, C.static
Int); } /// 29: ok | 80 { C.staticInt = 1; Expect.equals(2, ++C?.staticInt); Expect.equals(2, C.static
Int); } //# 29: ok |
| 81 { h.C.staticInt = 1; Expect.equals(2, ++h.C?.staticInt); Expect.equals(2, h.C.
staticInt); } /// 30: ok | 81 { h.C.staticInt = 1; Expect.equals(2, ++h.C?.staticInt); Expect.equals(2, h.C.
staticInt); } //# 30: ok |
| 82 | 82 |
| 83 // The static type of ++e1?.v is the same as the static type of e1.v + 1. | 83 // The static type of ++e1?.v is the same as the static type of e1.v + 1. |
| 84 { D d = new D(new E()); F f = ++d?.v; Expect.identical(d.v, f); } /// 11: ok | 84 { D d = new D(new E()); F f = ++d?.v; Expect.identical(d.v, f); } //# 11: ok |
| 85 { D d = new D(new E()); H h = ++d?.v; Expect.identical(d.v, h); } /// 12: stat
ic type warning | 85 { D d = new D(new E()); H h = ++d?.v; Expect.identical(d.v, h); } //# 12: stat
ic type warning |
| 86 { D.staticE = new E(); F f = ++D?.staticE; Expect.identical(D.staticE, f); } /
// 31: ok | 86 { D.staticE = new E(); F f = ++D?.staticE; Expect.identical(D.staticE, f); } /
/# 31: ok |
| 87 { h.D.staticE = new h.E(); h.F f = ++h.D?.staticE; Expect.identical(h.D.static
E, f); } /// 32: ok | 87 { h.D.staticE = new h.E(); h.F f = ++h.D?.staticE; Expect.identical(h.D.static
E, f); } //# 32: ok |
| 88 { D.staticE = new E(); H h = ++D?.staticE; Expect.identical(D.staticE, h); } /
// 33: static type warning | 88 { D.staticE = new E(); H h = ++D?.staticE; Expect.identical(D.staticE, h); } /
/# 33: static type warning |
| 89 { h.D.staticE = new h.E(); h.H hh = ++h.D?.staticE; Expect.identical(h.D.stati
cE, hh); } /// 34: static type warning | 89 { h.D.staticE = new h.E(); h.H hh = ++h.D?.staticE; Expect.identical(h.D.stati
cE, hh); } //# 34: static type warning |
| 90 | 90 |
| 91 // --e1?.v is equivalent to e1?.v -= 1. | 91 // --e1?.v is equivalent to e1?.v -= 1. |
| 92 Expect.equals(null, --nullC()?.v); /// 13: ok | 92 Expect.equals(null, --nullC()?.v); //# 13: ok |
| 93 { C c = new C(1); Expect.equals(0, --c?.v); Expect.equals(0, c.v); } /// 14: o
k | 93 { C c = new C(1); Expect.equals(0, --c?.v); Expect.equals(0, c.v); } //# 14: o
k |
| 94 | 94 |
| 95 // --C?.v is equivalent to C?.v -= 1. | 95 // --C?.v is equivalent to C?.v -= 1. |
| 96 { C.staticInt = 1; Expect.equals(0, --C?.staticInt); Expect.equals(0, C.static
Int); } /// 35: ok | 96 { C.staticInt = 1; Expect.equals(0, --C?.staticInt); Expect.equals(0, C.static
Int); } //# 35: ok |
| 97 { h.C.staticInt = 1; Expect.equals(0, --h.C?.staticInt); Expect.equals(0, h.C.
staticInt); } /// 36: ok | 97 { h.C.staticInt = 1; Expect.equals(0, --h.C?.staticInt); Expect.equals(0, h.C.
staticInt); } //# 36: ok |
| 98 | 98 |
| 99 // The static type of --e1?.v is the same as the static type of e1.v - 1. | 99 // The static type of --e1?.v is the same as the static type of e1.v - 1. |
| 100 { D d = new D(new E()); F f = --d?.v; Expect.identical(d.v, f); } /// 15: ok | 100 { D d = new D(new E()); F f = --d?.v; Expect.identical(d.v, f); } //# 15: ok |
| 101 { D d = new D(new E()); H h = --d?.v; Expect.identical(d.v, h); } /// 16: stat
ic type warning | 101 { D d = new D(new E()); H h = --d?.v; Expect.identical(d.v, h); } //# 16: stat
ic type warning |
| 102 { D.staticE = new E(); F f = --D?.staticE; Expect.identical(D.staticE, f); } /
// 37: ok | 102 { D.staticE = new E(); F f = --D?.staticE; Expect.identical(D.staticE, f); } /
/# 37: ok |
| 103 { h.D.staticE = new h.E(); h.F f = --h.D?.staticE; Expect.identical(h.D.static
E, f); } /// 38: ok | 103 { h.D.staticE = new h.E(); h.F f = --h.D?.staticE; Expect.identical(h.D.static
E, f); } //# 38: ok |
| 104 { D.staticE = new E(); H h = --D?.staticE; Expect.identical(D.staticE, h); } /
// 39: static type warning | 104 { D.staticE = new E(); H h = --D?.staticE; Expect.identical(D.staticE, h); } /
/# 39: static type warning |
| 105 { h.D.staticE = new h.E(); h.H hh = --h.D?.staticE; Expect.identical(h.D.stati
cE, hh); } /// 40: static type warning | 105 { h.D.staticE = new h.E(); h.H hh = --h.D?.staticE; Expect.identical(h.D.stati
cE, hh); } //# 40: static type warning |
| 106 } | 106 } |
| OLD | NEW |