OLD | NEW |
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 // Test least upper bound through type checking of conditionals. | 5 // Test least upper bound through type checking of conditionals. |
6 | 6 |
7 class A { | 7 class A { |
8 var a; | 8 var a; |
9 } | 9 } |
10 class B { | 10 class B { |
(...skipping 19 matching lines...) Expand all Loading... |
30 | 30 |
31 void main() { | 31 void main() { |
32 testAB(new A(), new B()); | 32 testAB(new A(), new B()); |
33 testBC(new C(), new C()); | 33 testBC(new C(), new C()); |
34 testCD(new C(), new D()); | 34 testCD(new C(), new D()); |
35 testEE(new F<C>(new C()), new F<C>(new C())); | 35 testEE(new F<C>(new C()), new F<C>(new C())); |
36 testEF(new F<C>(new C()), new F<C>(new C())); | 36 testEF(new F<C>(new C()), new F<C>(new C())); |
37 } | 37 } |
38 | 38 |
39 void testAB(A a, B b) { | 39 void testAB(A a, B b) { |
40 A r1 = true ? a : b; /// 01: ok | 40 A r1 = true ? a : b; //# 01: ok |
41 B r2 = false ? a : b; /// 02: ok | 41 B r2 = false ? a : b; //# 02: ok |
42 (true ? a : b).a = 0; /// 03: static type warning | 42 (true ? a : b).a = 0; //# 03: static type warning |
43 (false ? a : b).b = 0; /// 04: static type warning | 43 (false ? a : b).b = 0; //# 04: static type warning |
44 var c = new C(); | 44 var c = new C(); |
45 (true ? a : c).a = 0; /// 05: ok | 45 (true ? a : c).a = 0; //# 05: ok |
46 (false ? c : b).b = 0; /// 06: ok | 46 (false ? c : b).b = 0; //# 06: ok |
47 } | 47 } |
48 | 48 |
49 void testBC(B b, C c) { | 49 void testBC(B b, C c) { |
50 B r1 = true ? b : c; /// 07: ok | 50 B r1 = true ? b : c; //# 07: ok |
51 C r2 = false ? b : c; /// 08: ok | 51 C r2 = false ? b : c; //# 08: ok |
52 (true ? b : c).b = 0; /// 09: ok | 52 (true ? b : c).b = 0; //# 09: ok |
53 (false ? b : c).c = 0; /// 10: static type warning | 53 (false ? b : c).c = 0; //# 10: static type warning |
54 var a = null; | 54 var a = null; |
55 (true ? b : a).b = 0; /// 11: ok | 55 (true ? b : a).b = 0; //# 11: ok |
56 (false ? a : b).c = 0; /// 12: ok | 56 (false ? a : b).c = 0; //# 12: ok |
57 (true ? c : a).b = 0; /// 13: ok | 57 (true ? c : a).b = 0; //# 13: ok |
58 (false ? a : c).c = 0; /// 14: ok | 58 (false ? a : c).c = 0; //# 14: ok |
59 } | 59 } |
60 | 60 |
61 void testCD(C c, D d) { | 61 void testCD(C c, D d) { |
62 C r1 = true ? c : d; /// 15: ok | 62 C r1 = true ? c : d; //# 15: ok |
63 D r2 = false ? c : d; /// 16: ok | 63 D r2 = false ? c : d; //# 16: ok |
64 (true ? c : d).b = 0; /// 17: ok | 64 (true ? c : d).b = 0; //# 17: ok |
65 (false ? c : d).b = 0; /// 18: ok | 65 (false ? c : d).b = 0; //# 18: ok |
66 (true ? c : d).c = 0; /// 19: static type warning | 66 (true ? c : d).c = 0; //# 19: static type warning |
67 (false ? c : d).d = 0; /// 20: static type warning | 67 (false ? c : d).d = 0; //# 20: static type warning |
68 } | 68 } |
69 | 69 |
70 void testEE(E<B> e, E<C> f) { | 70 void testEE(E<B> e, E<C> f) { |
71 // The least upper bound of E<B> and E<C> is Object since the supertypes are | 71 // The least upper bound of E<B> and E<C> is Object since the supertypes are |
72 // {E<B>, Object} for E<B> and | 72 // {E<B>, Object} for E<B> and |
73 // {E<C>, Object} for E<C> and | 73 // {E<C>, Object} for E<C> and |
74 // Object is the most specific type in the intersection of the supertypes. | 74 // Object is the most specific type in the intersection of the supertypes. |
75 E<B> r1 = true ? e : f; /// 21: ok | 75 E<B> r1 = true ? e : f; //# 21: ok |
76 F<C> r2 = false ? e : f; /// 22: ok | 76 F<C> r2 = false ? e : f; //# 22: ok |
77 try { | 77 try { |
78 A r3 = true ? e : f; /// 23: ok | 78 A r3 = true ? e : f; //# 23: ok |
79 B r4 = false ? e : f; /// 24: ok | 79 B r4 = false ? e : f; //# 24: ok |
80 } catch (e) { | 80 } catch (e) { |
81 // Type error in checked mode. | 81 // Type error in checked mode. |
82 } | 82 } |
83 (true ? e : f).e = null; /// 25: static type warning | 83 (true ? e : f).e = null; //# 25: static type warning |
84 (false ? e : f).e = null; /// 26: static type warning | 84 (false ? e : f).e = null; //# 26: static type warning |
85 } | 85 } |
86 | 86 |
87 void testEF(E<B> e, F<C> f) { | 87 void testEF(E<B> e, F<C> f) { |
88 // The least upper bound of E<B> and F<C> is Object since the supertypes are | 88 // The least upper bound of E<B> and F<C> is Object since the supertypes are |
89 // {E<B>, Object} for E<B> and | 89 // {E<B>, Object} for E<B> and |
90 // {F<C>, E<C>, Object} for F<C> and | 90 // {F<C>, E<C>, Object} for F<C> and |
91 // Object is the most specific type in the intersection of the supertypes. | 91 // Object is the most specific type in the intersection of the supertypes. |
92 E<B> r1 = true ? e : f; /// 27: ok | 92 E<B> r1 = true ? e : f; //# 27: ok |
93 F<C> r2 = false ? e : f; /// 28: ok | 93 F<C> r2 = false ? e : f; //# 28: ok |
94 try { | 94 try { |
95 A r3 = true ? e : f; /// 29: ok | 95 A r3 = true ? e : f; //# 29: ok |
96 B r4 = false ? e : f; /// 30: ok | 96 B r4 = false ? e : f; //# 30: ok |
97 } catch (e) { | 97 } catch (e) { |
98 // Type error in checked mode. | 98 // Type error in checked mode. |
99 } | 99 } |
100 var r5; | 100 var r5; |
101 r5 = (true ? e : f).e; /// 31: static type warning | 101 r5 = (true ? e : f).e; //# 31: static type warning |
102 r5 = (false ? e : f).f; /// 32: static type warning | 102 r5 = (false ? e : f).f; //# 32: static type warning |
103 } | 103 } |
OLD | NEW |