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 class A { | 7 class A { |
8 var a = "a"; | 8 var a = "a"; |
9 A operator +(int i) => this; | 9 A operator +(int i) => this; |
10 } | 10 } |
(...skipping 12 matching lines...) Expand all Loading... |
23 var c = ""; | 23 var c = ""; |
24 var d = ""; | 24 var d = ""; |
25 } | 25 } |
26 | 26 |
27 func(x) => true; | 27 func(x) => true; |
28 | 28 |
29 void main() { | 29 void main() { |
30 test1(); | 30 test1(); |
31 test2(); | 31 test2(); |
32 test3(); | 32 test3(); |
| 33 test3a(); |
33 test4(); | 34 test4(); |
34 test5(); | 35 test5(); |
35 test6(); | 36 test6(); |
| 37 test6a(); |
36 test7(); | 38 test7(); |
37 test8(); | 39 test8(); |
38 test9(); | 40 test9(); |
39 test10(); | 41 test10(); |
40 test11(); | 42 test11(); |
41 test12(); | 43 test12(); |
42 } | 44 } |
43 | 45 |
44 void test1() { | 46 void test1() { |
45 A a = new E(); | 47 A a = new E(); |
(...skipping 26 matching lines...) Expand all Loading... |
72 print(a.a); | 74 print(a.a); |
73 print(a.b); /// 03: static type warning | 75 print(a.b); /// 03: static type warning |
74 void foo() { | 76 void foo() { |
75 a = new D(); | 77 a = new D(); |
76 } | 78 } |
77 print(a.a); | 79 print(a.a); |
78 print(a.b); /// 04: static type warning | 80 print(a.b); /// 04: static type warning |
79 } | 81 } |
80 } | 82 } |
81 | 83 |
| 84 void test3a() { |
| 85 A a = new E(); |
| 86 void foo() { |
| 87 a = new D(); |
| 88 } |
| 89 if ((((a)) is B)) { |
| 90 print(a.a); |
| 91 print(a.b); /// 15: static type warning |
| 92 void foo() { |
| 93 a = new D(); |
| 94 } |
| 95 print(a.a); |
| 96 print(a.b); /// 16: static type warning |
| 97 } |
| 98 } |
| 99 |
82 void test4() { | 100 void test4() { |
83 A a = new E(); | 101 A a = new E(); |
84 if (a is B) { | 102 if (a is B) { |
85 func(() => a.b); /// 05: ok | 103 func(() => a.b); /// 05: ok |
86 print(a.a); | 104 print(a.a); |
87 print(a.b); | 105 print(a.b); |
88 } | 106 } |
89 } | 107 } |
90 | 108 |
91 void test5() { | 109 void test5() { |
92 A a = new E(); | 110 A a = new E(); |
93 if (a is B) { | 111 if (a is B) { |
94 func(() => a.b); /// 06: static type warning | 112 func(() => a.b); /// 06: static type warning |
95 print(a.a); | 113 print(a.a); |
96 } | 114 } |
97 a = null; | 115 a = null; |
98 } | 116 } |
99 | 117 |
100 void test6() { | 118 void test6() { |
101 A a = new E(); | 119 A a = new E(); |
102 if (a is B) { | 120 if (a is B) { |
103 func(() => a); | 121 func(() => a); |
104 print(a.a); | 122 print(a.a); |
105 print(a.b); /// 07: static type warning | 123 print(a.b); /// 07: static type warning |
106 } | 124 } |
107 a = null; | 125 a = null; |
108 } | 126 } |
109 | 127 |
| 128 void test6a() { |
| 129 A a = new E(); |
| 130 if (((a) is B)) { |
| 131 func(() => a); |
| 132 print(a.a); |
| 133 print(a.b); /// 14: static type warning |
| 134 } |
| 135 a = null; |
| 136 } |
| 137 |
110 void test7() { | 138 void test7() { |
111 A a = new E(); | 139 A a = new E(); |
112 if (a is B && func(() => a)) { | 140 if (a is B && func(() => a)) { |
113 print(a.a); | 141 print(a.a); |
114 print(a.b); /// 08: ok | 142 print(a.b); /// 08: ok |
115 } | 143 } |
116 a = null; | 144 a = null; |
117 } | 145 } |
118 | 146 |
119 void test8() { | 147 void test8() { |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
152 | 180 |
153 void test12() { | 181 void test12() { |
154 A a = new E(); | 182 A a = new E(); |
155 if (a is B) { | 183 if (a is B) { |
156 func(() => a++); | 184 func(() => a++); |
157 print(a.a); | 185 print(a.a); |
158 print(a.b); /// 13: static type warning | 186 print(a.b); /// 13: static type warning |
159 } | 187 } |
160 a = null; | 188 a = null; |
161 } | 189 } |
OLD | NEW |