OLD | NEW |
(Empty) | |
| 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 |
| 3 // BSD-style license that can be found in the LICENSE file. |
| 4 |
| 5 // Verify semantics of the ?. operator when it appears in a postincrement or |
| 6 // preincrement expression (or a postdecrement or predecrement expression). |
| 7 |
| 8 import "package:expect/expect.dart"; |
| 9 import "conditional_access_helper.dart" as h; |
| 10 |
| 11 class C { |
| 12 int v; |
| 13 C(this.v); |
| 14 static int staticInt; |
| 15 } |
| 16 |
| 17 class D { |
| 18 E v; |
| 19 D(this.v); |
| 20 static E staticE; |
| 21 } |
| 22 |
| 23 class E { |
| 24 G operator+(int i) => new I(); |
| 25 G operator-(int i) => new I(); |
| 26 } |
| 27 |
| 28 class F {} |
| 29 |
| 30 class G extends E implements F {} |
| 31 |
| 32 class H {} |
| 33 |
| 34 class I extends G implements H {} |
| 35 |
| 36 C nullC() => null; |
| 37 |
| 38 main() { |
| 39 // Make sure the "none" test fails if assignment to "?." is not implemented. |
| 40 // This makes status files easier to maintain. |
| 41 nullC()?.v = 1; |
| 42 |
| 43 // e1?.v++ is equivalent to ((x) => x == null ? null : x.v++)(e1). |
| 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 |
| 46 |
| 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 |
| 49 { h.C.staticInt = 1; Expect.equals(1, h.C?.staticInt++); Expect.equals(2, h.C.
staticInt); } /// 18: ok |
| 50 |
| 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 |
| 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 |
| 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 |
| 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 |
| 59 // e1?.v-- is equivalent to ((x) => x == null ? null : x.v--)(e1). |
| 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 |
| 62 |
| 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 |
| 65 { h.C.staticInt = 1; Expect.equals(1, h.C?.staticInt--); Expect.equals(0, h.C.
staticInt); } /// 24: ok |
| 66 |
| 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 |
| 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 |
| 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 |
| 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 |
| 75 // ++e1?.v is equivalent to e1?.v += 1. |
| 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 |
| 78 |
| 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 |
| 81 { h.C.staticInt = 1; Expect.equals(2, ++h.C?.staticInt); Expect.equals(2, h.C.
staticInt); } /// 30: ok |
| 82 |
| 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 |
| 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 |
| 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 |
| 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 |
| 91 // --e1?.v is equivalent to e1?.v -= 1. |
| 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 |
| 94 |
| 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 |
| 97 { h.C.staticInt = 1; Expect.equals(0, --h.C?.staticInt); Expect.equals(0, h.C.
staticInt); } /// 36: ok |
| 98 |
| 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 |
| 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 |
| 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 |
| 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 } |
OLD | NEW |