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 type promotion of locals potentially mutated in closures. | 5 // Test type promotion of locals potentially mutated in closures. |
6 | 6 |
7 import "package:meta/meta.dart" show virtual; | 7 import "package:meta/meta.dart" show virtual; |
8 | 8 |
9 class A { | 9 class A { |
10 @virtual var a = "a"; | 10 @virtual |
| 11 var a = "a"; |
11 A operator +(int i) => this; | 12 A operator +(int i) => this; |
12 } | 13 } |
| 14 |
13 class B extends A { | 15 class B extends A { |
14 @virtual var b = "b"; | 16 @virtual |
| 17 var b = "b"; |
15 } | 18 } |
| 19 |
16 class C extends B { | 20 class C extends B { |
17 @virtual var c = "c"; | 21 @virtual |
| 22 var c = "c"; |
18 } | 23 } |
| 24 |
19 class D extends A { | 25 class D extends A { |
20 @virtual var d = "d"; | 26 @virtual |
| 27 var d = "d"; |
21 } | 28 } |
| 29 |
22 class E extends D implements C { | 30 class E extends D implements C { |
23 var a = ""; | 31 var a = ""; |
24 var b = ""; | 32 var b = ""; |
25 var c = ""; | 33 var c = ""; |
26 var d = ""; | 34 var d = ""; |
27 } | 35 } |
28 | 36 |
29 func(x) => true; | 37 func(x) => true; |
30 | 38 |
31 void main() { | 39 void main() { |
(...skipping 22 matching lines...) Expand all Loading... |
54 void foo() { | 62 void foo() { |
55 a = new D(); | 63 a = new D(); |
56 } | 64 } |
57 } | 65 } |
58 | 66 |
59 void test2() { | 67 void test2() { |
60 A a = new E(); | 68 A a = new E(); |
61 void foo() { | 69 void foo() { |
62 a = new D(); | 70 a = new D(); |
63 } | 71 } |
| 72 |
64 if (a is B) { | 73 if (a is B) { |
65 print(a.a); | 74 print(a.a); |
66 print(a.b); //# 02: static type warning | 75 print(a.b); //# 02: static type warning |
67 } | 76 } |
68 } | 77 } |
69 | 78 |
70 void test3() { | 79 void test3() { |
71 A a = new E(); | 80 A a = new E(); |
72 void foo() { | 81 void foo() { |
73 a = new D(); | 82 a = new D(); |
74 } | 83 } |
| 84 |
75 if (a is B) { | 85 if (a is B) { |
76 print(a.a); | 86 print(a.a); |
77 print(a.b); //# 03: static type warning | 87 print(a.b); //# 03: static type warning |
78 void foo() { | 88 void foo() { |
79 a = new D(); | 89 a = new D(); |
80 } | 90 } |
| 91 |
81 print(a.a); | 92 print(a.a); |
82 print(a.b); //# 04: static type warning | 93 print(a.b); //# 04: static type warning |
83 } | 94 } |
84 } | 95 } |
85 | 96 |
86 void test3a() { | 97 void test3a() { |
87 A a = new E(); | 98 A a = new E(); |
88 void foo() { | 99 void foo() { |
89 a = new D(); | 100 a = new D(); |
90 } | 101 } |
| 102 |
91 if ((((a)) is B)) { | 103 if ((((a)) is B)) { |
92 print(a.a); | 104 print(a.a); |
93 print(a.b); //# 15: static type warning | 105 print(a.b); //# 15: static type warning |
94 void foo() { | 106 void foo() { |
95 a = new D(); | 107 a = new D(); |
96 } | 108 } |
| 109 |
97 print(a.a); | 110 print(a.a); |
98 print(a.b); //# 16: static type warning | 111 print(a.b); //# 16: static type warning |
99 } | 112 } |
100 } | 113 } |
101 | 114 |
102 void test4() { | 115 void test4() { |
103 A a = new E(); | 116 A a = new E(); |
104 if (a is B) { | 117 if (a is B) { |
105 func(() => a.b); //# 05: ok | 118 func(() => a.b); //# 05: ok |
106 print(a.a); | 119 print(a.a); |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
143 print(a.a); | 156 print(a.a); |
144 print(a.b); //# 08: ok | 157 print(a.b); //# 08: ok |
145 } | 158 } |
146 a = null; | 159 a = null; |
147 } | 160 } |
148 | 161 |
149 void test8() { | 162 void test8() { |
150 A a = new E(); | 163 A a = new E(); |
151 if (a is B | 164 if (a is B |
152 && func(() => a.b) //# 09: static type warning | 165 && func(() => a.b) //# 09: static type warning |
153 ) { | 166 ) { |
154 print(a.a); | 167 print(a.a); |
155 } | 168 } |
156 a = null; | 169 a = null; |
157 } | 170 } |
158 | 171 |
159 void test9() { | 172 void test9() { |
160 A a = new E(); | 173 A a = new E(); |
161 var b = a is B ? func(() => a.b) : false; //# 10: static type warning | 174 var b = a is B ? func(() => a.b) : false; //# 10: static type warning |
162 a = null; | 175 a = null; |
163 } | 176 } |
(...skipping 18 matching lines...) Expand all Loading... |
182 | 195 |
183 void test12() { | 196 void test12() { |
184 A a = new E(); | 197 A a = new E(); |
185 if (a is B) { | 198 if (a is B) { |
186 func(() => a++); | 199 func(() => a++); |
187 print(a.a); | 200 print(a.a); |
188 print(a.b); //# 13: static type warning | 201 print(a.b); //# 13: static type warning |
189 } | 202 } |
190 a = null; | 203 a = null; |
191 } | 204 } |
OLD | NEW |