OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 package com.google.dart.compiler.end2end.inc; | 4 package com.google.dart.compiler.end2end.inc; |
5 | 5 |
6 import com.google.common.collect.Lists; | 6 import com.google.common.collect.Lists; |
7 import com.google.common.collect.Maps; | 7 import com.google.common.collect.Maps; |
8 import com.google.common.collect.Sets; | 8 import com.google.common.collect.Sets; |
9 import com.google.dart.compiler.CompilerTestCase; | 9 import com.google.dart.compiler.CompilerTestCase; |
10 import com.google.dart.compiler.DartCompilationError; | 10 import com.google.dart.compiler.DartCompilationError; |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
84 appSource = new MemoryLibrarySource(APP); | 84 appSource = new MemoryLibrarySource(APP); |
85 appSource.setContent( | 85 appSource.setContent( |
86 APP, | 86 APP, |
87 makeCode( | 87 makeCode( |
88 "// filler filler filler filler filler filler filler filler filler f
iller filler", | 88 "// filler filler filler filler filler filler filler filler filler f
iller filler", |
89 "library application;", | 89 "library application;", |
90 "part 'A.dart';", | 90 "part 'A.dart';", |
91 "part 'B.dart';", | 91 "part 'B.dart';", |
92 "part 'C.dart';", | 92 "part 'C.dart';", |
93 "")); | 93 "")); |
94 appSource.setContent("A.dart", "part of application;"); | 94 appSource.setContent("A.dart", ""); |
95 appSource.setContent("B.dart", "part of application;"); | 95 appSource.setContent("B.dart", ""); |
96 appSource.setContent("C.dart", "part of application;"); | 96 appSource.setContent("C.dart", ""); |
97 } | 97 } |
98 | 98 |
99 @Override | 99 @Override |
100 protected void tearDown() { | 100 protected void tearDown() { |
101 config = null; | 101 config = null; |
102 provider = null; | 102 provider = null; |
103 appSource = null; | 103 appSource = null; |
104 errors.clear(); | 104 errors.clear(); |
105 units.clear(); | 105 units.clear(); |
106 } | 106 } |
107 | 107 |
108 /** | 108 /** |
109 * "not_hole" is referenced using "super" qualifier, so is not affected by dec
laring top-level | 109 * "not_hole" is referenced using "super" qualifier, so is not affected by dec
laring top-level |
110 * field with same name. | 110 * field with same name. |
111 */ | 111 */ |
112 public void test_useQualifiedFieldReference_ignoreTopLevelDeclaration() { | 112 public void test_useQualifiedFieldReference_ignoreTopLevelDeclaration() { |
113 appSource.setContent( | 113 appSource.setContent( |
114 "B.dart", | 114 "B.dart", |
115 makeCode( | 115 makeCode( |
116 "// filler filler filler filler filler filler filler filler filler f
iller filler", | 116 "// filler filler filler filler filler filler filler filler filler f
iller filler", |
117 "part of application;", | |
118 "class A {", | 117 "class A {", |
119 " int not_hole;", | 118 " int not_hole;", |
120 "}", | 119 "}", |
121 "")); | 120 "")); |
122 appSource.setContent( | 121 appSource.setContent( |
123 "C.dart", | 122 "C.dart", |
124 makeCode( | 123 makeCode( |
125 "// filler filler filler filler filler filler filler filler filler f
iller filler", | 124 "// filler filler filler filler filler filler filler filler filler f
iller filler", |
126 "part of application;", | |
127 "class B extends A {", | 125 "class B extends A {", |
128 " int bar() {", | 126 " int bar() {", |
129 " return super.not_hole;", // qualified reference | 127 " return super.not_hole;", // qualified reference |
130 " }", | 128 " }", |
131 "}", | 129 "}", |
132 "")); | 130 "")); |
133 compile(); | 131 compile(); |
134 assertErrors(errors); | 132 assertErrors(errors); |
135 // Update units and compile. | 133 // Update units and compile. |
136 appSource.setContent( | 134 appSource.setContent( |
137 "A.dart", | 135 "A.dart", |
138 makeCode( | 136 makeCode( |
139 "// filler filler filler filler filler filler filler filler filler f
iller filler", | 137 "// filler filler filler filler filler filler filler filler filler f
iller filler", |
140 "part of application;", | |
141 "int not_hole;", | 138 "int not_hole;", |
142 "")); | 139 "")); |
143 compile(); | 140 compile(); |
144 // TODO(scheglov) Fix this after 1159 | 141 // TODO(scheglov) Fix this after 1159 |
145 //assertErrors(errors, errEx(ResolverErrorCode.DUPLICATE_LOCAL_VARIABLE_WARN
ING, -1, 7, 20)); | 142 //assertErrors(errors, errEx(ResolverErrorCode.DUPLICATE_LOCAL_VARIABLE_WARN
ING, -1, 7, 20)); |
146 // B should be compiled because it now conflicts with A. | 143 // B should be compiled because it now conflicts with A. |
147 // C should not be compiled, because it reference "not_hole" field, not top-
level variable. | 144 // C should not be compiled, because it reference "not_hole" field, not top-
level variable. |
148 didWrite("A.dart", EXTENSION_TIMESTAMP); | 145 didWrite("A.dart", EXTENSION_TIMESTAMP); |
149 didWrite("B.dart", EXTENSION_TIMESTAMP); | 146 didWrite("B.dart", EXTENSION_TIMESTAMP); |
150 didNotWrite("C.dart", EXTENSION_TIMESTAMP); | 147 didNotWrite("C.dart", EXTENSION_TIMESTAMP); |
151 assertAppBuilt(); | 148 assertAppBuilt(); |
152 } | 149 } |
153 | 150 |
154 /** | 151 /** |
155 * Referenced "hole" identifier can not be resolved, but when we declare it in
A, then B should be | 152 * Referenced "hole" identifier can not be resolved, but when we declare it in
A, then B should be |
156 * recompiled and error message disappear. | 153 * recompiled and error message disappear. |
157 */ | 154 */ |
158 public void test_useUnresolvedField_recompileOnTopLevelDeclaration() { | 155 public void test_useUnresolvedField_recompileOnTopLevelDeclaration() { |
159 appSource.setContent( | 156 appSource.setContent( |
160 "B.dart", | 157 "B.dart", |
161 makeCode( | 158 makeCode( |
162 "// filler filler filler filler filler filler filler filler filler f
iller filler", | 159 "// filler filler filler filler filler filler filler filler filler f
iller filler", |
163 "part of application;", | |
164 "class A {", | 160 "class A {", |
165 " int foo() {", | 161 " int foo() {", |
166 " return hole;", // no such field | 162 " return hole;", // no such field |
167 " }", | 163 " }", |
168 "}", | 164 "}", |
169 "")); | 165 "")); |
170 compile(); | 166 compile(); |
171 assertErrors(errors, errEx(TypeErrorCode.CANNOT_BE_RESOLVED, 5, 12, 4)); | 167 assertErrors(errors, errEx(TypeErrorCode.CANNOT_BE_RESOLVED, 4, 12, 4)); |
172 // Update units and compile. | 168 // Update units and compile. |
173 appSource.setContent( | 169 appSource.setContent( |
174 "A.dart", | 170 "A.dart", |
175 makeCode( | 171 makeCode( |
176 "// filler filler filler filler filler filler filler filler filler f
iller filler", | 172 "// filler filler filler filler filler filler filler filler filler f
iller filler", |
177 "part of application;", | |
178 "int hole;", | 173 "int hole;", |
179 "")); | 174 "")); |
180 compile(); | 175 compile(); |
181 // A and B should be compiled. | 176 // A and B should be compiled. |
182 didWrite("A.dart", EXTENSION_TIMESTAMP); | 177 didWrite("A.dart", EXTENSION_TIMESTAMP); |
183 didWrite("B.dart", EXTENSION_TIMESTAMP); | 178 didWrite("B.dart", EXTENSION_TIMESTAMP); |
184 assertAppBuilt(); | 179 assertAppBuilt(); |
185 // "hole" was filled with top-level field. | 180 // "hole" was filled with top-level field. |
186 assertErrors(errors); | 181 assertErrors(errors); |
187 } | 182 } |
188 | 183 |
189 /** | 184 /** |
190 * Test for "hole" feature. If we use unqualified invocation and add/remove to
p-level method, this | 185 * Test for "hole" feature. If we use unqualified invocation and add/remove to
p-level method, this |
191 * should cause compilation of invocation unit. | 186 * should cause compilation of invocation unit. |
192 */ | 187 */ |
193 public void test_isMethodHole_useUnqualifiedInvocation() throws Exception { | 188 public void test_isMethodHole_useUnqualifiedInvocation() throws Exception { |
194 appSource.setContent( | 189 appSource.setContent( |
195 "B.dart", | 190 "B.dart", |
196 makeCode( | 191 makeCode( |
197 "// filler filler filler filler filler filler filler filler filler f
iller filler", | 192 "// filler filler filler filler filler filler filler filler filler f
iller filler", |
198 "part of application;", | |
199 "class A {", | 193 "class A {", |
200 " foo() {}", | 194 " foo() {}", |
201 "}", | 195 "}", |
202 "")); | 196 "")); |
203 appSource.setContent( | 197 appSource.setContent( |
204 "C.dart", | 198 "C.dart", |
205 makeCode( | 199 makeCode( |
206 "// filler filler filler filler filler filler filler filler filler f
iller filler", | 200 "// filler filler filler filler filler filler filler filler filler f
iller filler", |
207 "part of application;", | |
208 "class B extends A {", | 201 "class B extends A {", |
209 " int bar() {", | 202 " int bar() {", |
210 " foo();", // unqualified invocation | 203 " foo();", // unqualified invocation |
211 " }", | 204 " }", |
212 "}", | 205 "}", |
213 "")); | 206 "")); |
214 compile(); | 207 compile(); |
215 assertErrors(errors); | 208 assertErrors(errors); |
216 // Declare top-level foo(), now invocation of foo() in B should be bound to
this top-level. | 209 // Declare top-level foo(), now invocation of foo() in B should be bound to
this top-level. |
217 { | 210 { |
218 appSource.setContent( | 211 appSource.setContent( |
219 "A.dart", | 212 "A.dart", |
220 makeCode( | 213 makeCode( |
221 "// filler filler filler filler filler filler filler filler filler
filler filler", | 214 "// filler filler filler filler filler filler filler filler filler
filler filler", |
222 "part of application;", | |
223 "foo() {}", | 215 "foo() {}", |
224 "")); | 216 "")); |
225 compile(); | 217 compile(); |
226 // B should be compiled because it also declares foo(), so produces "shado
w" conflict. | 218 // B should be compiled because it also declares foo(), so produces "shado
w" conflict. |
227 // C should be compiled because it has unqualified invocation which was de
clared in A. | 219 // C should be compiled because it has unqualified invocation which was de
clared in A. |
228 didWrite("A.dart", EXTENSION_TIMESTAMP); | 220 didWrite("A.dart", EXTENSION_TIMESTAMP); |
229 didWrite("B.dart", EXTENSION_TIMESTAMP); | 221 didWrite("B.dart", EXTENSION_TIMESTAMP); |
230 didWrite("C.dart", EXTENSION_TIMESTAMP); | 222 didWrite("C.dart", EXTENSION_TIMESTAMP); |
231 assertAppBuilt(); | 223 assertAppBuilt(); |
232 } | 224 } |
233 // Wait, because analysis is so fast that may be A will have same time as ol
d artifact. | 225 // Wait, because analysis is so fast that may be A will have same time as ol
d artifact. |
234 Thread.sleep(5); | 226 Thread.sleep(5); |
235 // Remove top-level foo(), so invocation of foo() in B should be bound to th
e super class. | 227 // Remove top-level foo(), so invocation of foo() in B should be bound to th
e super class. |
236 { | 228 { |
237 appSource.setContent("A.dart", "part of application;"); | 229 appSource.setContent("A.dart", ""); |
238 compile(); | 230 compile(); |
239 // B should be compiled because it also declares foo(), so produces "shado
w" conflict. | 231 // B should be compiled because it also declares foo(), so produces "shado
w" conflict. |
240 // C should be compiled because it has unqualified invocation which was de
clared in A. | 232 // C should be compiled because it has unqualified invocation which was de
clared in A. |
241 didWrite("A.dart", EXTENSION_TIMESTAMP); | 233 didWrite("A.dart", EXTENSION_TIMESTAMP); |
242 didWrite("B.dart", EXTENSION_TIMESTAMP); | 234 didWrite("B.dart", EXTENSION_TIMESTAMP); |
243 didWrite("C.dart", EXTENSION_TIMESTAMP); | 235 didWrite("C.dart", EXTENSION_TIMESTAMP); |
244 } | 236 } |
245 } | 237 } |
246 | 238 |
247 /** | 239 /** |
248 * Test for "hole" feature. If we use qualified invocation and add/remove top-
level method, this | 240 * Test for "hole" feature. If we use qualified invocation and add/remove top-
level method, this |
249 * should not cause compilation of invocation unit. | 241 * should not cause compilation of invocation unit. |
250 */ | 242 */ |
251 public void test_notMethodHole_useQualifiedInvocation() { | 243 public void test_notMethodHole_useQualifiedInvocation() { |
252 appSource.setContent( | 244 appSource.setContent( |
253 "B.dart", | 245 "B.dart", |
254 makeCode( | 246 makeCode( |
255 "// filler filler filler filler filler filler filler filler filler f
iller filler", | 247 "// filler filler filler filler filler filler filler filler filler f
iller filler", |
256 "part of application;", | |
257 "class A {", | 248 "class A {", |
258 " foo() {}", | 249 " foo() {}", |
259 "}", | 250 "}", |
260 "")); | 251 "")); |
261 appSource.setContent( | 252 appSource.setContent( |
262 "C.dart", | 253 "C.dart", |
263 makeCode( | 254 makeCode( |
264 "// filler filler filler filler filler filler filler filler filler f
iller filler", | 255 "// filler filler filler filler filler filler filler filler filler f
iller filler", |
265 "part of application;", | |
266 "class B extends A {", | 256 "class B extends A {", |
267 " int bar() {", | 257 " int bar() {", |
268 " super.foo();", // qualified invocation | 258 " super.foo();", // qualified invocation |
269 " }", | 259 " }", |
270 "}", | 260 "}", |
271 "")); | 261 "")); |
272 compile(); | 262 compile(); |
273 assertErrors(errors); | 263 assertErrors(errors); |
274 // Declare top-level foo(), but it is ignored. | 264 // Declare top-level foo(), but it is ignored. |
275 { | 265 { |
276 appSource.setContent( | 266 appSource.setContent( |
277 "A.dart", | 267 "A.dart", |
278 makeCode( | 268 makeCode( |
279 "// filler filler filler filler filler filler filler filler filler
filler filler", | 269 "// filler filler filler filler filler filler filler filler filler
filler filler", |
280 "part of application;", | |
281 "foo() {}", | 270 "foo() {}", |
282 "")); | 271 "")); |
283 compile(); | 272 compile(); |
284 // B should be compiled because it also declares foo(), so produces "shado
w" conflict. | 273 // B should be compiled because it also declares foo(), so produces "shado
w" conflict. |
285 // C should not be compiled because. | 274 // C should not be compiled because. |
286 didWrite("A.dart", EXTENSION_TIMESTAMP); | 275 didWrite("A.dart", EXTENSION_TIMESTAMP); |
287 didWrite("B.dart", EXTENSION_TIMESTAMP); | 276 didWrite("B.dart", EXTENSION_TIMESTAMP); |
288 didNotWrite("C.dart", EXTENSION_TIMESTAMP); | 277 didNotWrite("C.dart", EXTENSION_TIMESTAMP); |
289 assertAppBuilt(); | 278 assertAppBuilt(); |
290 } | 279 } |
291 } | 280 } |
292 | 281 |
293 /** | 282 /** |
294 * Test for "hole" feature. If we use unqualified access and add/remove top-le
vel field, this | 283 * Test for "hole" feature. If we use unqualified access and add/remove top-le
vel field, this |
295 * should cause compilation of invocation unit. | 284 * should cause compilation of invocation unit. |
296 */ | 285 */ |
297 public void test_fieldHole_useUnqualifiedAccess() throws Exception { | 286 public void test_fieldHole_useUnqualifiedAccess() throws Exception { |
298 appSource.setContent( | 287 appSource.setContent( |
299 "B.dart", | 288 "B.dart", |
300 makeCode( | 289 makeCode( |
301 "// filler filler filler filler filler filler filler filler filler f
iller filler", | 290 "// filler filler filler filler filler filler filler filler filler f
iller filler", |
302 "part of application;", | |
303 "class A {", | 291 "class A {", |
304 " var foo;", | 292 " var foo;", |
305 "}", | 293 "}", |
306 "")); | 294 "")); |
307 appSource.setContent( | 295 appSource.setContent( |
308 "C.dart", | 296 "C.dart", |
309 makeCode( | 297 makeCode( |
310 "// filler filler filler filler filler filler filler filler filler f
iller filler", | 298 "// filler filler filler filler filler filler filler filler filler f
iller filler", |
311 "part of application;", | |
312 "class B extends A {", | 299 "class B extends A {", |
313 " int bar() {", | 300 " int bar() {", |
314 " foo = 0;", // unqualified access | 301 " foo = 0;", // unqualified access |
315 " }", | 302 " }", |
316 "}", | 303 "}", |
317 "")); | 304 "")); |
318 compile(); | 305 compile(); |
319 assertErrors(errors); | 306 assertErrors(errors); |
320 // Declare top-level "foo", now access to "foo" in B should be bound to this
top-level. | 307 // Declare top-level "foo", now access to "foo" in B should be bound to this
top-level. |
321 { | 308 { |
322 appSource.setContent( | 309 appSource.setContent( |
323 "A.dart", | 310 "A.dart", |
324 makeCode( | 311 makeCode( |
325 "// filler filler filler filler filler filler filler filler filler
filler filler", | 312 "// filler filler filler filler filler filler filler filler filler
filler filler", |
326 "part of application;", | |
327 "var foo;", | 313 "var foo;", |
328 "")); | 314 "")); |
329 compile(); | 315 compile(); |
330 // B should be compiled because it also declares "foo", so produces "shado
w" conflict. | 316 // B should be compiled because it also declares "foo", so produces "shado
w" conflict. |
331 // C should be compiled because it has unqualified invocation which was de
clared in A. | 317 // C should be compiled because it has unqualified invocation which was de
clared in A. |
332 didWrite("A.dart", EXTENSION_TIMESTAMP); | 318 didWrite("A.dart", EXTENSION_TIMESTAMP); |
333 didWrite("B.dart", EXTENSION_TIMESTAMP); | 319 didWrite("B.dart", EXTENSION_TIMESTAMP); |
334 didWrite("C.dart", EXTENSION_TIMESTAMP); | 320 didWrite("C.dart", EXTENSION_TIMESTAMP); |
335 assertAppBuilt(); | 321 assertAppBuilt(); |
336 } | 322 } |
337 // Wait, because analysis is so fast that may be A will have same time as ol
d artifact. | 323 // Wait, because analysis is so fast that may be A will have same time as ol
d artifact. |
338 Thread.sleep(5); | 324 Thread.sleep(5); |
339 // Remove top-level "foo", so access to "foo" in B should be bound to the su
per class. | 325 // Remove top-level "foo", so access to "foo" in B should be bound to the su
per class. |
340 { | 326 { |
341 appSource.setContent("A.dart", "part of application;"); | 327 appSource.setContent("A.dart", ""); |
342 compile(); | 328 compile(); |
343 // B should be compiled because it also declares "foo", so produces "shado
w" conflict. | 329 // B should be compiled because it also declares "foo", so produces "shado
w" conflict. |
344 // C should be compiled because it has unqualified access which was declar
ed in A. | 330 // C should be compiled because it has unqualified access which was declar
ed in A. |
345 didWrite("A.dart", EXTENSION_TIMESTAMP); | 331 didWrite("A.dart", EXTENSION_TIMESTAMP); |
346 didWrite("B.dart", EXTENSION_TIMESTAMP); | 332 didWrite("B.dart", EXTENSION_TIMESTAMP); |
347 didWrite("C.dart", EXTENSION_TIMESTAMP); | 333 didWrite("C.dart", EXTENSION_TIMESTAMP); |
348 } | 334 } |
349 } | 335 } |
350 | 336 |
351 /** | 337 /** |
352 * Test for "hole" feature. If we use qualified access and add/remove top-leve
l field, this should | 338 * Test for "hole" feature. If we use qualified access and add/remove top-leve
l field, this should |
353 * not cause compilation of invocation unit. | 339 * not cause compilation of invocation unit. |
354 */ | 340 */ |
355 public void test_fieldHole_useQualifiedAccess() { | 341 public void test_fieldHole_useQualifiedAccess() { |
356 appSource.setContent( | 342 appSource.setContent( |
357 "B.dart", | 343 "B.dart", |
358 makeCode( | 344 makeCode( |
359 "// filler filler filler filler filler filler filler filler filler f
iller filler", | 345 "// filler filler filler filler filler filler filler filler filler f
iller filler", |
360 "part of application;", | |
361 "class A {", | 346 "class A {", |
362 " var foo;", | 347 " var foo;", |
363 "}", | 348 "}", |
364 "")); | 349 "")); |
365 appSource.setContent( | 350 appSource.setContent( |
366 "C.dart", | 351 "C.dart", |
367 makeCode( | 352 makeCode( |
368 "// filler filler filler filler filler filler filler filler filler f
iller filler", | 353 "// filler filler filler filler filler filler filler filler filler f
iller filler", |
369 "part of application;", | |
370 "class B extends A {", | 354 "class B extends A {", |
371 " int bar() {", | 355 " int bar() {", |
372 " super.foo = 0;", // qualified access | 356 " super.foo = 0;", // qualified access |
373 " }", | 357 " }", |
374 "}", | 358 "}", |
375 "")); | 359 "")); |
376 compile(); | 360 compile(); |
377 assertErrors(errors); | 361 assertErrors(errors); |
378 // Declare top-level "foo", but it is ignored. | 362 // Declare top-level "foo", but it is ignored. |
379 { | 363 { |
380 appSource.setContent( | 364 appSource.setContent( |
381 "A.dart", | 365 "A.dart", |
382 makeCode( | 366 makeCode( |
383 "// filler filler filler filler filler filler filler filler filler
filler filler", | 367 "// filler filler filler filler filler filler filler filler filler
filler filler", |
384 "part of application;", | |
385 "var foo;", | 368 "var foo;", |
386 "")); | 369 "")); |
387 compile(); | 370 compile(); |
388 // B should be compiled because it also declares "foo", so produces "shado
w" conflict. | 371 // B should be compiled because it also declares "foo", so produces "shado
w" conflict. |
389 // C should not be compiled because it has qualified access to "foo". | 372 // C should not be compiled because it has qualified access to "foo". |
390 didWrite("A.dart", EXTENSION_TIMESTAMP); | 373 didWrite("A.dart", EXTENSION_TIMESTAMP); |
391 didWrite("B.dart", EXTENSION_TIMESTAMP); | 374 didWrite("B.dart", EXTENSION_TIMESTAMP); |
392 didNotWrite("C.dart", EXTENSION_TIMESTAMP); | 375 didNotWrite("C.dart", EXTENSION_TIMESTAMP); |
393 assertAppBuilt(); | 376 assertAppBuilt(); |
394 } | 377 } |
395 } | 378 } |
396 | 379 |
397 public void test_declareTopLevel_conflictWithLocalVariable() { | 380 public void test_declareTopLevel_conflictWithLocalVariable() { |
398 appSource.setContent( | 381 appSource.setContent( |
399 "B.dart", | 382 "B.dart", |
400 makeCode( | 383 makeCode( |
401 "// filler filler filler filler filler filler filler filler filler f
iller filler", | 384 "// filler filler filler filler filler filler filler filler filler f
iller filler", |
402 "part of application;", | |
403 "methodB() {", | 385 "methodB() {", |
404 " var symbolDependency_foo;", | 386 " var symbolDependency_foo;", |
405 "}")); | 387 "}")); |
406 compile(); | 388 compile(); |
407 assertErrors(errors); | 389 assertErrors(errors); |
408 // Update units and compile. | 390 // Update units and compile. |
409 appSource.setContent( | 391 appSource.setContent( |
410 "A.dart", | 392 "A.dart", |
411 makeCode( | 393 makeCode( |
412 "// filler filler filler filler filler filler filler filler filler f
iller filler", | 394 "// filler filler filler filler filler filler filler filler filler f
iller filler", |
413 "part of application;", | |
414 "var symbolDependency_foo;")); | 395 "var symbolDependency_foo;")); |
415 compile(); | 396 compile(); |
416 // Now there is top-level declarations conflict between A and B. | 397 // Now there is top-level declarations conflict between A and B. |
417 // So, B should be compiled. | 398 // So, B should be compiled. |
418 didWrite("B.dart", EXTENSION_TIMESTAMP); | 399 didWrite("B.dart", EXTENSION_TIMESTAMP); |
419 // But application should be build. | 400 // But application should be build. |
420 assertAppBuilt(); | 401 assertAppBuilt(); |
421 } | 402 } |
422 | 403 |
423 public void test_undeclareTopLevel_conflictWithLocalVariable() { | 404 public void test_undeclareTopLevel_conflictWithLocalVariable() { |
424 appSource.setContent( | 405 appSource.setContent( |
425 "A.dart", | 406 "A.dart", |
426 makeCode( | 407 makeCode( |
427 "// filler filler filler filler filler filler filler filler filler f
iller filler", | 408 "// filler filler filler filler filler filler filler filler filler f
iller filler", |
428 "part of application;", | |
429 "var duplicate;")); | 409 "var duplicate;")); |
430 appSource.setContent( | 410 appSource.setContent( |
431 "B.dart", | 411 "B.dart", |
432 makeCode( | 412 makeCode( |
433 "// filler filler filler filler filler filler filler filler filler f
iller filler", | 413 "// filler filler filler filler filler filler filler filler filler f
iller filler", |
434 "part of application;", | |
435 "bar() {", | 414 "bar() {", |
436 " var duplicate;", | 415 " var duplicate;", |
437 "}")); | 416 "}")); |
438 compile(); | 417 compile(); |
439 // Update units and compile. | 418 // Update units and compile. |
440 appSource.setContent("A.dart", "part of application;"); | 419 appSource.setContent("A.dart", ""); |
441 compile(); | 420 compile(); |
442 // Top-level declaration in A was removed, so no conflict. | 421 // Top-level declaration in A was removed, so no conflict. |
443 // So: | 422 // So: |
444 // ... B should be recompiled. | 423 // ... B should be recompiled. |
445 didWrite("B.dart", EXTENSION_TIMESTAMP); | 424 didWrite("B.dart", EXTENSION_TIMESTAMP); |
446 // ... but application should be rebuild. | 425 // ... but application should be rebuild. |
447 assertAppBuilt(); | 426 assertAppBuilt(); |
448 } | 427 } |
449 | 428 |
450 /** | 429 /** |
451 * Removes A, so changes set of top level units and forces compilation. | 430 * Removes A, so changes set of top level units and forces compilation. |
452 */ | 431 */ |
453 public void test_removeOneSource() { | 432 public void test_removeOneSource() { |
454 appSource.setContent( | 433 appSource.setContent( |
455 "A.dart", | 434 "A.dart", |
456 makeCode( | 435 makeCode( |
457 "// filler filler filler filler filler filler filler filler filler f
iller filler", | 436 "// filler filler filler filler filler filler filler filler filler f
iller filler", |
458 "part of application;", | |
459 "var duplicate;")); | 437 "var duplicate;")); |
460 appSource.setContent( | 438 appSource.setContent( |
461 "B.dart", | 439 "B.dart", |
462 makeCode( | 440 makeCode( |
463 "// filler filler filler filler filler filler filler filler filler f
iller filler", | 441 "// filler filler filler filler filler filler filler filler filler f
iller filler", |
464 "part of application;", | |
465 "bar() {", | 442 "bar() {", |
466 " var duplicate;", | 443 " var duplicate;", |
467 "}")); | 444 "}")); |
468 compile(); | 445 compile(); |
469 // Exclude A and compile. | 446 // Exclude A and compile. |
470 appSource.setContent( | 447 appSource.setContent( |
471 APP, | 448 APP, |
472 makeCode( | 449 makeCode( |
473 "// filler filler filler filler filler filler filler filler filler f
iller filler", | 450 "// filler filler filler filler filler filler filler filler filler f
iller filler", |
474 "library app;", | 451 "library app;", |
475 "part 'B.dart';", | 452 "part 'B.dart';", |
476 "")); | 453 "")); |
477 compile(); | 454 compile(); |
478 // Now there is top-level declarations conflict between A and B. | 455 // Now there is top-level declarations conflict between A and B. |
479 // So: | 456 // So: |
480 // ... B should be recompiled. | 457 // ... B should be recompiled. |
481 didWrite("B.dart", EXTENSION_TIMESTAMP); | 458 didWrite("B.dart", EXTENSION_TIMESTAMP); |
482 // ... but application should be rebuild. | 459 // ... but application should be rebuild. |
483 didWrite(APP, EXTENSION_DEPS); | 460 didWrite(APP, EXTENSION_DEPS); |
484 } | 461 } |
485 | 462 |
486 public void test_declareField_conflictWithLocalVariable() { | 463 public void test_declareField_conflictWithLocalVariable() { |
487 appSource.setContent( | 464 appSource.setContent( |
488 "A.dart", | 465 "A.dart", |
489 makeCode( | 466 makeCode( |
490 "// filler filler filler filler filler filler filler filler filler f
iller filler", | 467 "// filler filler filler filler filler filler filler filler filler f
iller filler", |
491 "part of application;", | |
492 "class A {", | 468 "class A {", |
493 "}", | 469 "}", |
494 "")); | 470 "")); |
495 appSource.setContent( | 471 appSource.setContent( |
496 "B.dart", | 472 "B.dart", |
497 makeCode( | 473 makeCode( |
498 "// filler filler filler filler filler filler filler filler filler f
iller filler", | 474 "// filler filler filler filler filler filler filler filler filler f
iller filler", |
499 "part of application;", | |
500 "class B extends A {", | 475 "class B extends A {", |
501 " foo() {", | 476 " foo() {", |
502 " var bar;", | 477 " var bar;", |
503 " }", | 478 " }", |
504 "}", | 479 "}", |
505 "")); | 480 "")); |
506 compile(); | 481 compile(); |
507 assertErrors(errors); | 482 assertErrors(errors); |
508 // Update units and compile. | 483 // Update units and compile. |
509 appSource.setContent( | 484 appSource.setContent( |
510 "A.dart", | 485 "A.dart", |
511 makeCode( | 486 makeCode( |
512 "// filler filler filler filler filler filler filler filler filler f
iller filler", | 487 "// filler filler filler filler filler filler filler filler filler f
iller filler", |
513 "part of application;", | |
514 "class A {", | 488 "class A {", |
515 " var bar;", | 489 " var bar;", |
516 "}", | 490 "}", |
517 "")); | 491 "")); |
518 compile(); | 492 compile(); |
519 // B depends on A class, so compiled. | 493 // B depends on A class, so compiled. |
520 didWrite("B.dart", EXTENSION_TIMESTAMP); | 494 didWrite("B.dart", EXTENSION_TIMESTAMP); |
521 assertAppBuilt(); | 495 assertAppBuilt(); |
522 } | 496 } |
523 | 497 |
524 public void test_declareTopLevelVariable_conflictOtherTopLevelVariable() { | 498 public void test_declareTopLevelVariable_conflictOtherTopLevelVariable() { |
525 appSource.setContent( | 499 appSource.setContent( |
526 "A.dart", | 500 "A.dart", |
527 makeCode( | 501 makeCode( |
528 "// filler filler filler filler filler filler filler filler filler f
iller filler", | 502 "// filler filler filler filler filler filler filler filler filler f
iller filler", |
529 "part of application;", | |
530 "var conflict;", | 503 "var conflict;", |
531 "")); | 504 "")); |
532 compile(); | 505 compile(); |
533 assertErrors(errors); | 506 assertErrors(errors); |
534 // Update units and compile. | 507 // Update units and compile. |
535 appSource.setContent( | 508 appSource.setContent( |
536 "B.dart", | 509 "B.dart", |
537 makeCode( | 510 makeCode( |
538 "// filler filler filler filler filler filler filler filler filler f
iller filler", | 511 "// filler filler filler filler filler filler filler filler filler f
iller filler", |
539 "part of application;", | |
540 "var conflict;", | 512 "var conflict;", |
541 "")); | 513 "")); |
542 compile(); | 514 compile(); |
543 // A symbols intersect with new B symbols, so we compile A too. | 515 // A symbols intersect with new B symbols, so we compile A too. |
544 // Both A and B have errors. | 516 // Both A and B have errors. |
545 assertErrors( | 517 assertErrors( |
546 errors, | 518 errors, |
547 errEx("A.dart", ResolverErrorCode.DUPLICATE_TOP_LEVEL_DECLARATION, 3, 5,
8), | 519 errEx("A.dart", ResolverErrorCode.DUPLICATE_TOP_LEVEL_DECLARATION, 2, 5,
8), |
548 errEx("B.dart", ResolverErrorCode.DUPLICATE_TOP_LEVEL_DECLARATION, 3, 5,
8)); | 520 errEx("B.dart", ResolverErrorCode.DUPLICATE_TOP_LEVEL_DECLARATION, 2, 5,
8)); |
549 } | 521 } |
550 | 522 |
551 /** | 523 /** |
552 * Test that invalid "import" is reported as any other error between "unitAbou
tToCompile" and | 524 * Test that invalid "import" is reported as any other error between "unitAbou
tToCompile" and |
553 * "unitCompiled". | 525 * "unitCompiled". |
554 */ | 526 */ |
555 public void test_reportMissingImport() throws Exception { | 527 public void test_reportMissingImport() throws Exception { |
556 appSource.setContent( | 528 appSource.setContent( |
557 APP, | 529 APP, |
558 makeCode( | 530 makeCode( |
(...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
818 } | 790 } |
819 /** | 791 /** |
820 * <p> | 792 * <p> |
821 * http://code.google.com/p/dart/issues/detail?id=3532 | 793 * http://code.google.com/p/dart/issues/detail?id=3532 |
822 */ | 794 */ |
823 public void test_includeSameUnitTwice() throws Exception { | 795 public void test_includeSameUnitTwice() throws Exception { |
824 appSource.setContent( | 796 appSource.setContent( |
825 "A.dart", | 797 "A.dart", |
826 makeCode( | 798 makeCode( |
827 "// filler filler filler filler filler filler filler filler filler f
iller filler", | 799 "// filler filler filler filler filler filler filler filler filler f
iller filler", |
828 "part of application;", | |
829 "")); | 800 "")); |
830 appSource.setContent( | 801 appSource.setContent( |
831 APP, | 802 APP, |
832 makeCode( | 803 makeCode( |
833 "// filler filler filler filler filler filler filler filler filler f
iller filler", | 804 "// filler filler filler filler filler filler filler filler filler f
iller filler", |
834 "library application;", | 805 "library application;", |
835 "part 'A.dart';", | 806 "part 'A.dart';", |
836 "part 'A.dart';", | 807 "part 'A.dart';", |
837 "")); | 808 "")); |
838 // do compile, no errors expected | 809 // do compile, no errors expected |
(...skipping 661 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1500 "library application;", | 1471 "library application;", |
1501 "import 'A.dart' as mylib;", | 1472 "import 'A.dart' as mylib;", |
1502 "final A = mylib.B;", | 1473 "final A = mylib.B;", |
1503 "")); | 1474 "")); |
1504 // do compile, no errors expected | 1475 // do compile, no errors expected |
1505 compile(); | 1476 compile(); |
1506 assertErrors(errors); | 1477 assertErrors(errors); |
1507 } | 1478 } |
1508 | 1479 |
1509 /** | 1480 /** |
1510 * Part should have one and only one directive - "part of". | |
1511 */ | |
1512 public void test_partDirectives_otherThenPartOf() throws Exception { | |
1513 appSource.setContent( | |
1514 "A.dart", | |
1515 makeCode( | |
1516 "// filler filler filler filler filler filler filler filler filler f
iller filler", | |
1517 "library A;", | |
1518 "")); | |
1519 appSource.setContent( | |
1520 APP, | |
1521 makeCode( | |
1522 "// filler filler filler filler filler filler filler filler filler f
iller filler", | |
1523 "library application;", | |
1524 "part 'A.dart';", | |
1525 "")); | |
1526 // do compile | |
1527 compile(); | |
1528 assertErrors(errors, errEx(DartCompilerErrorCode.ILLEGAL_DIRECTIVES_IN_SOURC
ED_UNIT, 2, 1, 10)); | |
1529 } | |
1530 | |
1531 /** | |
1532 * Part should have one and only one directive - "part of". | |
1533 */ | |
1534 public void test_partDirectives_noPartOf() throws Exception { | |
1535 appSource.setContent( | |
1536 "A.dart", | |
1537 makeCode( | |
1538 "// filler filler filler filler filler filler filler filler filler f
iller filler", | |
1539 "")); | |
1540 appSource.setContent( | |
1541 APP, | |
1542 makeCode( | |
1543 "// filler filler filler filler filler filler filler filler filler f
iller filler", | |
1544 "library application;", | |
1545 "part 'A.dart';", | |
1546 "")); | |
1547 // do compile | |
1548 compile(); | |
1549 assertErrors(errors, errEx(DartCompilerErrorCode.MISSING_PART_OF_DIRECTIVE,
-1, -1, 0)); | |
1550 } | |
1551 | |
1552 /** | |
1553 * Part should have one and only one directive - "part of". | |
1554 */ | |
1555 public void test_partDirectives_wrongNameInPartOf() throws Exception { | |
1556 appSource.setContent( | |
1557 "A.dart", | |
1558 makeCode( | |
1559 "// filler filler filler filler filler filler filler filler filler f
iller filler", | |
1560 "part of Z;", | |
1561 "")); | |
1562 appSource.setContent( | |
1563 APP, | |
1564 makeCode( | |
1565 "// filler filler filler filler filler filler filler filler filler f
iller filler", | |
1566 "library application;", | |
1567 "part 'A.dart';", | |
1568 "")); | |
1569 // do compile | |
1570 compile(); | |
1571 assertErrors( | |
1572 errors, | |
1573 errEx(DartCompilerErrorCode.WRONG_PART_OF_NAME, 2, 1, 10), | |
1574 errEx(TypeErrorCode.CANNOT_BE_RESOLVED, 2, 9, 1)); | |
1575 } | |
1576 | |
1577 /** | |
1578 * Internals of Dart use "dart-ext:" import scheme, and these libraries are al
lowed to use | 1481 * Internals of Dart use "dart-ext:" import scheme, and these libraries are al
lowed to use |
1579 * "native". New import syntax. | 1482 * "native". New import syntax. |
1580 */ | 1483 */ |
1581 public void test_useNative_withDartExt_new() throws Exception { | 1484 public void test_useNative_withDartExt_new() throws Exception { |
1582 appSource.setContent( | 1485 appSource.setContent( |
1583 APP, | 1486 APP, |
1584 makeCode( | 1487 makeCode( |
1585 "// filler filler filler filler filler filler filler filler filler f
iller filler", | 1488 "// filler filler filler filler filler filler filler filler filler f
iller filler", |
1586 "library A;", | 1489 "library A;", |
1587 "import 'dart-ext:test_extension';", | 1490 "import 'dart-ext:test_extension';", |
1588 "class A {", | 1491 "class A {", |
1589 " static int ifNull(a, b) native 'TestExtension_IfNull';", | 1492 " static int ifNull(a, b) native 'TestExtension_IfNull';", |
1590 "}", | 1493 "}", |
1591 "")); | 1494 "")); |
1592 // do compile, no errors expected | 1495 // do compile, no errors expected |
1593 compile(); | 1496 compile(); |
1594 assertErrors(errors); | 1497 assertErrors(errors); |
1595 } | 1498 } |
1596 | 1499 |
1597 /** | 1500 /** |
1598 * Internals of Dart use "dart-ext:" import scheme, and these libraries are al
lowed to use | 1501 * Internals of Dart use "dart-ext:" import scheme, and these libraries are al
lowed to use |
1599 * "native". Obsolete import syntax. | 1502 * "native". Obsolete import syntax. |
1600 */ | 1503 */ |
1601 public void test_useNative_withDartExt_obsolete() throws Exception { | 1504 public void test_useNative_withDartExt_obsolete() throws Exception { |
1602 appSource.setContent( | 1505 appSource.setContent( |
1603 APP, | 1506 APP, |
1604 makeCode( | 1507 makeCode( |
1605 "// filler filler filler filler filler filler filler filler filler f
iller filler", | 1508 "// filler filler filler filler filler filler filler filler filler f
iller filler", |
1606 "#library('A');", | 1509 "#library('A');", |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1672 private void didWrite(String sourceName, String extension) { | 1575 private void didWrite(String sourceName, String extension) { |
1673 String spec = sourceName + "/" + extension; | 1576 String spec = sourceName + "/" + extension; |
1674 assertTrue("Expected write: " + spec, provider.writes.contains(spec)); | 1577 assertTrue("Expected write: " + spec, provider.writes.contains(spec)); |
1675 } | 1578 } |
1676 | 1579 |
1677 private void didNotWrite(String sourceName, String extension) { | 1580 private void didNotWrite(String sourceName, String extension) { |
1678 String spec = sourceName + "/" + extension; | 1581 String spec = sourceName + "/" + extension; |
1679 assertFalse("Didn't expect write: " + spec, provider.writes.contains(spec)); | 1582 assertFalse("Didn't expect write: " + spec, provider.writes.contains(spec)); |
1680 } | 1583 } |
1681 } | 1584 } |
OLD | NEW |