OLD | NEW |
---|---|
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, 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 package com.google.dart.compiler.resolver; | 5 package com.google.dart.compiler.resolver; |
6 | 6 |
7 import com.google.common.base.Joiner; | 7 import com.google.common.base.Joiner; |
8 import com.google.dart.compiler.DartCompilationError; | 8 import com.google.dart.compiler.DartCompilationError; |
9 import com.google.dart.compiler.ErrorCode; | 9 import com.google.dart.compiler.ErrorCode; |
10 import com.google.dart.compiler.ast.DartClass; | 10 import com.google.dart.compiler.ast.DartClass; |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
110 | 110 |
111 /** | 111 /** |
112 * interface IA extends ID factory B {} | 112 * interface IA extends ID factory B {} |
113 * interface IB extends IA {} | 113 * interface IB extends IA {} |
114 * interface IC extends IA, IB {} | 114 * interface IC extends IA, IB {} |
115 * interface ID extends IB {} | 115 * interface ID extends IB {} |
116 * class A extends IA {} | 116 * class A extends IA {} |
117 * class B {} | 117 * class B {} |
118 */ | 118 */ |
119 public void testGetSubtypesWithInterfaceCycles() { | 119 public void testGetSubtypesWithInterfaceCycles() { |
120 DartClass ia = makeInterface("IA", makeTypes("ID"), makeType("B")); | 120 DartClass ia = makeInterface("IA", makeTypes("ID"), null); |
ahe
2011/12/15 09:02:13
I don't understand why you made this change.
zundel
2011/12/16 21:36:29
I added it back and made it actually test somethin
| |
121 DartClass ib = makeInterface("IB", makeTypes("IA"), null); | 121 DartClass ib = makeInterface("IB", makeTypes("IA"), null); |
122 DartClass ic = makeInterface("IC", makeTypes("IA", "IB"), null); | 122 DartClass ic = makeInterface("IC", makeTypes("IA", "IB"), null); |
123 DartClass id = makeInterface("ID", makeTypes("IB"), null); | 123 DartClass id = makeInterface("ID", makeTypes("IB"), null); |
124 | 124 |
125 DartClass a = makeClass("A", null, makeTypes("IA")); | 125 DartClass a = makeClass("A", null, makeTypes("IA")); |
126 DartClass b = makeClass("B", null); | 126 DartClass b = makeClass("B", null); |
127 | 127 |
128 Scope libScope = resolve(makeUnit(object, ia, ib, ic, id, a, b), getContext( )); | 128 Scope libScope = resolve(makeUnit(object, ia, ib, ic, id, a, b), getContext( )); |
129 ErrorCode[] expected = { | 129 ErrorCode[] expected = { |
130 ResolverErrorCode.CYCLIC_CLASS, | 130 ResolverErrorCode.CYCLIC_CLASS, |
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
302 public void testBadFactory() { | 302 public void testBadFactory() { |
303 // Another interface should be in scope to name 'foo' as a constructor | 303 // Another interface should be in scope to name 'foo' as a constructor |
304 resolveAndTest(Joiner.on("\n").join( | 304 resolveAndTest(Joiner.on("\n").join( |
305 "class Object {}", | 305 "class Object {}", |
306 "class Zebra {", | 306 "class Zebra {", |
307 " factory foo() {}", | 307 " factory foo() {}", |
308 "}"), | 308 "}"), |
309 ResolverErrorCode.NO_SUCH_TYPE_CONSTRUCTOR); | 309 ResolverErrorCode.NO_SUCH_TYPE_CONSTRUCTOR); |
310 } | 310 } |
311 | 311 |
312 public void testFactoryTypeArgs1() { | 312 |
313 public void testDefaultTypeArgs1() { | |
313 // Type arguments match | 314 // Type arguments match |
314 resolveAndTest(Joiner.on("\n").join( | 315 resolveAndTest(Joiner.on("\n").join( |
315 "class Object {}", | 316 "class Object {}", |
316 "interface int {}", | 317 "interface int {}", |
317 "interface A<T> factory B {", | 318 "interface A<T> default B<T> {", |
318 " A();", | 319 " A();", |
319 "}", | 320 "}", |
320 "class B implements A {", | 321 "class B<T> implements A<T> {", |
321 " A<T>() {}", | 322 " B() {}", |
322 "}")); | 323 "}")); |
323 } | 324 } |
324 | 325 |
325 public void testFactoryTypeArgs2() { | 326 public void testDefaultTypeArgs2() { |
326 // Type arguments match | 327 // Type arguments match |
327 resolveAndTest(Joiner.on("\n").join( | 328 resolveAndTest(Joiner.on("\n").join( |
328 "class Object {}", | 329 "class Object {}", |
329 "interface A<T> factory B {", | 330 "interface A<T> default B<T> {", |
330 "}", | 331 "}", |
331 "class B {", | 332 "class B<T> {", |
332 " factory A<T>.construct () {}", | 333 " factory A.construct () {}", |
333 "}")); | 334 "}")); |
334 } | 335 } |
335 | 336 |
336 public void testFactoryTypeArgs3() { | 337 public void testDefaultTypeArgs3() { |
337 // Type arguments match | 338 // Type arguments match |
338 resolveAndTest(Joiner.on("\n").join( | 339 resolveAndTest(Joiner.on("\n").join( |
339 "class Object {}", | 340 "class Object {}", |
340 "interface A<T> factory B {", | 341 "interface A<T> default B<T> {", |
341 "}", | 342 "}", |
342 "class B {", | 343 "class B<T> {", |
343 " B<T>() {}", | 344 " B() {}", |
344 "}")); | 345 "}")); |
345 } | 346 } |
346 | 347 |
347 public void testFactoryTypeArgsNew() { | 348 public void testDefaultTypeArgs4() { |
349 // Type arguments match | |
350 resolveAndTest(Joiner.on("\n").join( | |
351 "class Object {}", | |
352 "interface A<T> default B<T> {", | |
353 "}", | |
354 "class B<T> implements A<T> {", | |
355 " B() {}", | |
356 "}")); | |
357 } | |
358 | |
359 public void testDefaultTypeArgsNew() { | |
348 // Invoke constructor in factory method with type args | 360 // Invoke constructor in factory method with type args |
349 resolveAndTest(Joiner.on("\n").join( | 361 resolveAndTest(Joiner.on("\n").join( |
350 "class Object {}", | 362 "class Object {}", |
351 "interface int {}", | 363 "interface int {}", |
352 "interface A<T> factory B {", | 364 "interface A<T> default B<T> {", |
353 " A<T>();", | 365 " B();", |
354 "}", | 366 "}", |
355 "class C<T> implements A<T> {}", | 367 "class C<T> implements A<T> {}", |
356 "class B {", | 368 "class B<T> {", |
357 " factory A<T>() { return new C<T>();}", | 369 " factory B() { return new C<T>();}", |
358 "}")); | 370 "}")); |
359 } | 371 } |
360 | 372 |
361 public void testFactoryBadTypeArgsNew() { | 373 public void testFactoryBadTypeArgsNew1() { |
362 // Invoke constructor in factory method with (wrong) type args | 374 // Invoke constructor in factory method with (wrong) type args |
363 resolveAndTest(Joiner.on("\n").join( | 375 resolveAndTest(Joiner.on("\n").join( |
364 "class Object {}", | 376 "class Object {}", |
365 "interface int {}", | 377 "interface int {}", |
366 "interface A<T> factory B {", | 378 "interface A<T> default B<T> {", |
367 " A<T>();", | 379 " A();", |
368 "}", | 380 "}", |
369 "class C<T> implements A<T> {}", | 381 "class C<T> implements A<T> {}", |
370 "class B {", | 382 "class B<T> {", |
371 " factory A<T>() { return new C<K>();}", | 383 " factory A() { return new C<K>();}", |
372 "}"), | 384 "}"), |
373 ResolverErrorCode.NO_SUCH_TYPE); | 385 ResolverErrorCode.NO_SUCH_TYPE); |
374 } | 386 } |
375 | 387 |
376 public void disabledBadFactoryTypeArgs1() { | 388 public void testFactoryBadTypeArgsNew2() { |
377 // Type arguments don't match | 389 // Invoke constructor in factory method with (wrong) type args |
378 resolveAndTest(Joiner.on("\n").join( | 390 resolveAndTest(Joiner.on("\n").join( |
379 "class Object {}", | 391 "class Object {}", |
380 "interface A<T> factory B {", | 392 "interface int {}", |
381 " A<T>();", | 393 "interface A<T> default B {", |
394 " A();", | |
382 "}", | 395 "}", |
396 "class C<T> implements A<T> {}", | |
383 "class B {", | 397 "class B {", |
384 " A<T>() {}", | 398 " factory A() { return new C<int>();}", |
385 "}"), | 399 "}"), |
386 ResolverErrorCode.FACTORY_CONSTRUCTOR_TYPE_ARGS_DO_NOT_MATCH); | 400 ResolverErrorCode.DEFAULT_CLASS_MUST_HAVE_SAME_TYPE_PARAMS); |
ahe
2011/12/15 09:02:13
This test seems good, but you may also want to tes
zundel
2011/12/15 14:12:50
The spec is not very clear on when you need to spe
ahe
2011/12/15 14:20:53
You'd specify them for the interface "Map<K,V>" be
zundel
2011/12/16 21:36:29
Added those two (as cases that should pass w/o err
zundel
2011/12/16 21:36:29
Sure, but if you left them out, nothing would go w
| |
387 } | 401 } |
388 | 402 |
389 public void disabledBadFactoryTypeArgs2() { | 403 public void testFactoryBadTypeArgsNew3() { |
390 // Type arguments match | 404 // Invoke constructor in factory method with (wrong) type args |
ahe
2011/12/15 09:02:13
This test has multiple problems. I'm not sure what
| |
391 resolveAndTest(Joiner.on("\n").join( | 405 resolveAndTest(Joiner.on("\n").join( |
392 "class Object {}", | 406 "class Object {}", |
393 "interface A<T> factory B {", | 407 "interface int {}", |
408 "interface A<T> default B<K> {", | |
409 " A();", | |
394 "}", | 410 "}", |
395 "class B {", | 411 "class C<T> implements A<T> {}", |
396 " factory A<T>.construct () {}", | 412 "class B<K> {", |
ahe
2011/12/15 09:02:13
This is an error because:
"If I has n type parame
zundel
2011/12/16 21:36:29
I split this up into a couple of tests.
| |
413 " factory A() { return new C<int>();}", | |
ahe
2011/12/15 09:02:13
This is a warning because C<int> is not assignable
zundel
2011/12/16 21:36:29
Done.
| |
397 "}"), | 414 "}"), |
398 ResolverErrorCode.FACTORY_CONSTRUCTOR_TYPE_ARGS_DO_NOT_MATCH); | 415 ResolverErrorCode.TYPE_PARAMETER_DOES_NOT_MATCH); |
399 } | 416 } |
400 | 417 |
401 public void disabledBadFactoryTypeArgs3() { | 418 public void testFactoryBadTypeArgsNew4() { |
ahe
2011/12/15 09:02:13
Same problems as the above test.
| |
402 // Type arguments match | 419 // Invoke constructor in factory method with (wrong) type args |
403 resolveAndTest(Joiner.on("\n").join( | 420 resolveAndTest(Joiner.on("\n").join( |
404 "class Object {}", | 421 "class Object {}", |
405 "interface A<T> factory B {", | 422 "interface int {}", |
406 " A<T>();", | 423 "interface A<T,K> default B<K,T> {", |
424 " A();", | |
407 "}", | 425 "}", |
408 "class B implements A {", | 426 "class C<T,K> implements A<T,K> {}", |
409 " B() {}", | 427 "class B<K,T> {", |
428 " factory A() { return new C<int, Object>();}", | |
410 "}"), | 429 "}"), |
411 ResolverErrorCode.FACTORY_CONSTRUCTOR_TYPE_ARGS_DO_NOT_MATCH); | 430 ResolverErrorCode.TYPE_PARAMETER_DOES_NOT_MATCH, |
412 } | 431 ResolverErrorCode.TYPE_PARAMETER_DOES_NOT_MATCH); |
413 | |
414 public void disabledNonConstructorMethodTypeArgs() { | |
415 // Type arguments match | |
416 resolveAndTest(Joiner.on("\n").join( | |
417 "class Object {}", | |
418 "class A {", | |
419 " foo<T>() {}", | |
420 "}"), | |
421 ResolverErrorCode.TYPE_ARGS_ONLY_ON_CONSTRUCTORS); | |
422 } | 432 } |
423 | 433 |
424 public void testBadGenerativeConstructor1() { | 434 public void testBadGenerativeConstructor1() { |
425 resolveAndTest(Joiner.on("\n").join( | 435 resolveAndTest(Joiner.on("\n").join( |
426 "class Object { }", | 436 "class Object { }", |
427 "class B { }", | 437 "class B { }", |
428 "class A {", | 438 "class A {", |
429 " var val; ", | 439 " var val; ", |
430 " B.foo() : this.val = 1;", | 440 " B.foo() : this.val = 1;", |
431 "}"), | 441 "}"), |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
543 " T create() {", | 553 " T create() {", |
544 " return new T();", | 554 " return new T();", |
545 " }", | 555 " }", |
546 "}"), | 556 "}"), |
547 ResolverErrorCode.NEW_EXPRESSION_CANT_USE_TYPE_VAR); | 557 ResolverErrorCode.NEW_EXPRESSION_CANT_USE_TYPE_VAR); |
548 } | 558 } |
549 | 559 |
550 public void testNewExpression5() { | 560 public void testNewExpression5() { |
551 // More cowbell. (Foo<T> isn't a type yet) | 561 // More cowbell. (Foo<T> isn't a type yet) |
552 resolveAndTest(Joiner.on("\n").join( | 562 resolveAndTest(Joiner.on("\n").join( |
553 "class Object {}", | 563 "class Object {}", |
554 "class Foo<T> { }", | 564 "class Foo<T> { }", |
555 "class B {", | 565 "class B {", |
556 " foo() { return new Foo<T>(); }", | 566 " foo() { return new Foo<T>(); }", |
ahe
2011/12/15 09:02:13
I agree this is an error because T is not in scope
| |
557 "}"), | 567 "}"), |
558 ResolverErrorCode.NO_SUCH_TYPE); | 568 ResolverErrorCode.NO_SUCH_TYPE); |
569 } | |
570 | |
571 public void testNewExpression6() { | |
572 resolveAndTest(Joiner.on("\n").join( | |
573 "class Object {}", | |
574 "interface int {}", | |
575 "interface A<T> default B<T> {", | |
576 " A.construct(); ", | |
577 "}", | |
578 "class B<T> implements A<T> {", | |
579 " B() { }", | |
580 " factory B.construct() { return new B<T>(); }", | |
581 "}")); | |
559 } | 582 } |
560 | 583 |
561 public void test_noSuchType_field() throws Exception { | 584 public void test_noSuchType_field() throws Exception { |
562 resolveAndTest(Joiner.on("\n").join( | 585 resolveAndTest(Joiner.on("\n").join( |
563 "class Object {}", | 586 "class Object {}", |
564 "class MyClass {", | 587 "class MyClass {", |
565 " Unknown field;", | 588 " Unknown field;", |
566 "}"), | 589 "}"), |
567 TypeErrorCode.NO_SUCH_TYPE); | 590 TypeErrorCode.NO_SUCH_TYPE); |
568 } | 591 } |
(...skipping 371 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
940 "class Object {}", | 963 "class Object {}", |
941 "interface Interface {", | 964 "interface Interface {", |
942 " foo([y,x]);", | 965 " foo([y,x]);", |
943 "}", | 966 "}", |
944 "class Class implements Interface {", | 967 "class Class implements Interface {", |
945 " foo([x,y]) {}", // error | 968 " foo([x,y]) {}", // error |
946 "}"), | 969 "}"), |
947 ResolverErrorCode.CANNOT_OVERRIDE_METHOD_ORDER_NAMED_PARAMS); | 970 ResolverErrorCode.CANNOT_OVERRIDE_METHOD_ORDER_NAMED_PARAMS); |
948 } | 971 } |
949 } | 972 } |
OLD | NEW |