Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(5)

Side by Side Diff: tests/language/least_upper_bound_test.dart

Issue 52263003: Implement least upper bound. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Updated cf. comments. Created 7 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « tests/language/least_upper_bound_expansive_test.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // BSD-style license that can be found in the LICENSE file.
4
5 // Test least upper bound through type checking of conditionals.
6
7 class A {
8 var a;
9 }
10 class B {
11 var b;
12 }
13 class C extends B {
14 var c;
15 }
16 class D extends B {
17 var d;
18 }
19
20 class E<T> {
21 T e;
22
23 E(this.e);
24 }
25 class F<T> extends E<T> {
26 T f;
27
28 F(T f) : this.f = f, super(f);
29 }
30
31 void main() {
32 testAB(new A(), new B());
33 testBC(new C(), new C());
34 testCD(new C(), new D());
35 testEE(new F<C>(new C()), new F<C>(new C()));
36 testEF(new F<C>(new C()), new F<C>(new C()));
37 }
38
39 void testAB(A a, B b) {
40 A r1 = true ? a : b; /// 01: ok
41 B r2 = false ? a : b; /// 02: ok
42 (true ? a : b).a = 0; /// 03: static type warning
43 (false ? a : b).b = 0; /// 04: static type warning
44 var c = new C();
45 (true ? a : c).a = 0; /// 05: ok
46 (false ? c : b).b = 0; /// 06: ok
47 }
48
49 void testBC(B b, C c) {
50 B r1 = true ? b : c; /// 07: ok
51 C r2 = false ? b : c; /// 08: ok
52 (true ? b : c).b = 0; /// 09: ok
53 (false ? b : c).c = 0; /// 10: static type warning
54 var a = null;
55 (true ? b : a).b = 0; /// 11: ok
56 (false ? a : b).c = 0; /// 12: ok
57 (true ? c : a).b = 0; /// 13: ok
58 (false ? a : c).c = 0; /// 14: ok
59 }
60
61 void testCD(C c, D d) {
62 C r1 = true ? c : d; /// 15: ok
63 D r2 = false ? c : d; /// 16: ok
64 (true ? c : d).b = 0; /// 17: ok
65 (false ? c : d).b = 0; /// 18: ok
66 (true ? c : d).c = 0; /// 19: static type warning
67 (false ? c : d).d = 0; /// 20: static type warning
68 }
69
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
72 // {E<B>, Object} for E<B> and
73 // {E<C>, Object} for E<C> and
74 // Object is the most specific type in the intersection of the supertypes.
75 E<B> r1 = true ? e : f; /// 21: ok
76 F<C> r2 = false ? e : f; /// 22: ok
77 try {
78 A r3 = true ? e : f; /// 23: ok
79 B r4 = false ? e : f; /// 24: ok
80 } catch (e) {
81 // Type error in checked mode.
82 }
83 (true ? e : f).e = null; /// 25: static type warning
84 (false ? e : f).e = null; /// 26: static type warning
85 }
86
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
89 // {E<B>, Object} for E<B> and
90 // {F<C>, E<C>, Object} for F<C> and
91 // Object is the most specific type in the intersection of the supertypes.
92 E<B> r1 = true ? e : f; /// 27: ok
93 F<C> r2 = false ? e : f; /// 28: ok
94 try {
95 A r3 = true ? e : f; /// 29: ok
96 B r4 = false ? e : f; /// 30: ok
97 } catch (e) {
98 // Type error in checked mode.
99 }
100 var r5;
101 r5 = (true ? e : f).e; /// 31: static type warning
102 r5 = (false ? e : f).f; /// 32: static type warning
103 }
OLDNEW
« no previous file with comments | « tests/language/least_upper_bound_expansive_test.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698