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 | 4 |
5 import "dart:uri"; | 5 import "dart:uri"; |
6 import "../../../sdk/lib/_internal/compiler/implementation/elements/elements.dar
t"; | 6 import "../../../sdk/lib/_internal/compiler/implementation/elements/elements.dar
t"; |
7 import '../../../sdk/lib/_internal/compiler/implementation/scanner/scannerlib.da
rt'; | 7 import '../../../sdk/lib/_internal/compiler/implementation/scanner/scannerlib.da
rt'; |
8 import '../../../sdk/lib/_internal/compiler/implementation/source_file.dart'; | 8 import '../../../sdk/lib/_internal/compiler/implementation/source_file.dart'; |
9 import '../../../sdk/lib/_internal/compiler/implementation/types/types.dart'; | 9 import '../../../sdk/lib/_internal/compiler/implementation/types/types.dart'; |
10 import '../../../sdk/lib/_internal/compiler/implementation/tree/tree.dart'; | 10 import '../../../sdk/lib/_internal/compiler/implementation/tree/tree.dart'; |
(...skipping 493 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
504 result.string, // a.x = 'abc' | 504 result.string, // a.x = 'abc' |
505 result.bool, // a.y = true | 505 result.bool, // a.y = true |
506 result.nullType, // dynamic.x = null | 506 result.nullType, // dynamic.x = null |
507 result.double]); // dynamic.y = 3.14 | 507 result.double]); // dynamic.y = 3.14 |
508 result.checkFieldHasType('A', 'w', | 508 result.checkFieldHasType('A', 'w', |
509 [result.int, // new A(..., 42) | 509 [result.int, // new A(..., 42) |
510 result.bool, // a.y = true | 510 result.bool, // a.y = true |
511 result.double]); // dynamic.y = double | 511 result.double]); // dynamic.y = double |
512 } | 512 } |
513 | 513 |
514 testNamedParameters() { | 514 testOptionalNamedParameters() { |
515 final String source = r""" | 515 final String source = r""" |
516 class A { | 516 class A { |
517 var x, y, z, w; | 517 var x, y, z, w; |
518 A(this.x, {this.y, this.z, this.w}); | 518 A(this.x, {this.y, this.z, this.w}); |
519 } | 519 } |
| 520 class B { |
| 521 var x, y; |
| 522 B(this.x, {this.y}); |
| 523 } |
| 524 class C { |
| 525 var x, y; |
| 526 C(this.x, {this.y}); |
| 527 } |
| 528 class Test { |
| 529 var a, b, c, d; |
| 530 var e, f; |
| 531 var g, h; |
| 532 |
| 533 Test(this.a, this.b, this.c, this.d, |
| 534 this.e, this.f, |
| 535 this.g, this.h); |
| 536 |
| 537 f1(x, {y, z, w}) { |
| 538 a = x; |
| 539 b = y; |
| 540 c = z; |
| 541 d = w; |
| 542 } |
| 543 f2(x, {y}) { |
| 544 e = x; |
| 545 f = y; |
| 546 } |
| 547 f3(x, {y}) { |
| 548 g = x; |
| 549 h = y; |
| 550 } |
| 551 } |
| 552 class Foo { |
| 553 } |
520 main() { | 554 main() { |
| 555 // We want to test expiclitely for null later so we initialize all the |
| 556 // fields of Test with a placeholder type: Foo. |
| 557 var foo = new Foo(); |
| 558 var test = new Test(foo, foo, foo, foo, foo, foo, foo, foo); |
| 559 |
521 new A(42); | 560 new A(42); |
522 new A('abc', w: true, z: 42.0); | 561 new A('abc', w: true, z: 42.0); |
| 562 test.f1(42); |
| 563 test.f1('abc', w: true, z: 42.0); |
| 564 |
| 565 new B('abc', y: true); |
| 566 new B(1, 2); // too many positional arguments |
| 567 test.f2('abc', y: true); |
| 568 test.f2(1, 2); // too many positional arguments |
| 569 |
| 570 new C('abc', y: true); |
| 571 new C(1, z: 2); // non-existing named parameter |
| 572 test.f3('abc', y: true); |
| 573 test.f3(1, z: 2); // non-existing named parameter |
523 } | 574 } |
524 """; | 575 """; |
525 AnalysisResult result = analyze(source); | 576 AnalysisResult result = analyze(source); |
| 577 |
| 578 final foo = result.base('Foo'); |
| 579 final nil = new NullBaseType(); |
| 580 |
526 result.checkFieldHasType('A', 'x', [result.int, result.string]); | 581 result.checkFieldHasType('A', 'x', [result.int, result.string]); |
527 result.checkFieldHasType('A', 'y', [new NullBaseType()]); | 582 result.checkFieldHasType('A', 'y', [nil]); |
528 result.checkFieldHasType('A', 'z', [new NullBaseType(), result.double]); | 583 result.checkFieldHasType('A', 'z', [nil, result.double]); |
529 result.checkFieldHasType('A', 'w', [new NullBaseType(), result.bool]); | 584 result.checkFieldHasType('A', 'w', [nil, result.bool]); |
| 585 result.checkFieldHasType('Test', 'a', [foo, result.int, result.string]); |
| 586 result.checkFieldHasType('Test', 'b', [foo, nil]); |
| 587 result.checkFieldHasType('Test', 'c', [foo, nil, result.double]); |
| 588 result.checkFieldHasType('Test', 'd', [foo, nil, result.bool]); |
| 589 |
| 590 result.checkFieldHasType('B', 'x', [result.string]); |
| 591 result.checkFieldHasType('B', 'y', [result.bool]); |
| 592 result.checkFieldHasType('Test', 'e', [foo, result.string]); |
| 593 result.checkFieldHasType('Test', 'f', [foo, result.bool]); |
| 594 |
| 595 result.checkFieldHasType('C', 'x', [result.string]); |
| 596 result.checkFieldHasType('C', 'y', [result.bool]); |
| 597 result.checkFieldHasType('Test', 'g', [foo, result.string]); |
| 598 result.checkFieldHasType('Test', 'h', [foo, result.bool]); |
| 599 } |
| 600 |
| 601 testOptionalPositionalParameters() { |
| 602 final String source = r""" |
| 603 class A { |
| 604 var x, y, z, w; |
| 605 A(this.x, [this.y, this.z, this.w]); |
| 606 } |
| 607 class B { |
| 608 var x, y; |
| 609 B(this.x, [this.y]); |
| 610 } |
| 611 class Test { |
| 612 var a, b, c, d; |
| 613 var e, f; |
| 614 |
| 615 Test(this.a, this.b, this.c, this.d, |
| 616 this.e, this.f); |
| 617 |
| 618 f1(x, [y, z, w]) { |
| 619 a = x; |
| 620 b = y; |
| 621 c = z; |
| 622 d = w; |
| 623 } |
| 624 f2(x, [y]) { |
| 625 e = x; |
| 626 f = y; |
| 627 } |
| 628 } |
| 629 class Foo { |
| 630 } |
| 631 main() { |
| 632 // We want to test expiclitely for null later so we initialize all the |
| 633 // fields of Test with a placeholder type: Foo. |
| 634 var foo = new Foo(); |
| 635 var test = new Test(foo, foo, foo, foo, foo, foo); |
| 636 |
| 637 new A(42); |
| 638 new A('abc', true, 42.0); |
| 639 test.f1(42); |
| 640 test.f1('abc', true, 42.0); |
| 641 |
| 642 new B('a', true); |
| 643 new B(1, 2, 3); // too many arguments |
| 644 test.f2('a', true); |
| 645 test.f2(1, 2, 3); // too many arguments |
| 646 } |
| 647 """; |
| 648 AnalysisResult result = analyze(source); |
| 649 |
| 650 final foo = result.base('Foo'); |
| 651 final nil = new NullBaseType(); |
| 652 |
| 653 result.checkFieldHasType('A', 'x', [result.int, result.string]); |
| 654 result.checkFieldHasType('A', 'y', [nil, result.bool]); |
| 655 result.checkFieldHasType('A', 'z', [nil, result.double]); |
| 656 result.checkFieldHasType('A', 'w', [nil]); |
| 657 result.checkFieldHasType('Test', 'a', [foo, result.int, result.string]); |
| 658 result.checkFieldHasType('Test', 'b', [foo, nil, result.bool]); |
| 659 result.checkFieldHasType('Test', 'c', [foo, nil, result.double]); |
| 660 result.checkFieldHasType('Test', 'd', [foo, nil]); |
| 661 |
| 662 result.checkFieldHasType('B', 'x', [result.string]); |
| 663 result.checkFieldHasType('B', 'y', [result.bool]); |
| 664 result.checkFieldHasType('Test', 'e', [foo, result.string]); |
| 665 result.checkFieldHasType('Test', 'f', [foo, result.bool]); |
530 } | 666 } |
531 | 667 |
532 testListLiterals() { | 668 testListLiterals() { |
533 final String source = r""" | 669 final String source = r""" |
534 class A { | 670 class A { |
535 var x; | 671 var x; |
536 A(this.x); | 672 A(this.x); |
537 } | 673 } |
538 main() { | 674 main() { |
539 var x = []; | 675 var x = []; |
(...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
854 testNonRecusiveFunction(); | 990 testNonRecusiveFunction(); |
855 testRecusiveFunction(); | 991 testRecusiveFunction(); |
856 testMutuallyRecusiveFunction(); | 992 testMutuallyRecusiveFunction(); |
857 testSimpleSend(); | 993 testSimpleSend(); |
858 // testSendToClosureField(); // closures are not yet supported | 994 // testSendToClosureField(); // closures are not yet supported |
859 testSendToThis1(); | 995 testSendToThis1(); |
860 testSendToThis2(); | 996 testSendToThis2(); |
861 testConstructor(); | 997 testConstructor(); |
862 testGetters(); | 998 testGetters(); |
863 testSetters(); | 999 testSetters(); |
864 testNamedParameters(); | 1000 testOptionalNamedParameters(); |
| 1001 testOptionalPositionalParameters(); |
865 testListLiterals(); | 1002 testListLiterals(); |
866 testMapLiterals(); | 1003 testMapLiterals(); |
867 testReturn(); | 1004 testReturn(); |
868 // testNoReturn(); // right now we infer the empty type instead of null | 1005 // testNoReturn(); // right now we infer the empty type instead of null |
869 testArithmeticOperators(); | 1006 testArithmeticOperators(); |
870 testOperators(); | 1007 testOperators(); |
871 testCompoundOperators1(); | 1008 testCompoundOperators1(); |
872 testCompoundOperators2(); | 1009 testCompoundOperators2(); |
873 testSetIndexOperator(); | 1010 testSetIndexOperator(); |
874 testInequality(); | 1011 testInequality(); |
875 // testFieldInitialization(); // TODO(polux) | 1012 // testFieldInitialization(); // TODO(polux) |
876 testSendWithWrongArity(); | 1013 testSendWithWrongArity(); |
877 testBigTypesWidening1(); | 1014 testBigTypesWidening1(); |
878 testBigTypesWidening2(); | 1015 testBigTypesWidening2(); |
879 testDynamicIsAbsorbing(); | 1016 testDynamicIsAbsorbing(); |
880 } | 1017 } |
OLD | NEW |