Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(98)

Side by Side Diff: test/checker/checker_test.dart

Issue 1010893004: Allow S->T <: dynamic->T (Closed) Base URL: https://github.com/dart-lang/dev_compiler.git@master
Patch Set: Rebase and address comments Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « lib/src/testing.dart ('k') | test/codegen/expect/dart/_interceptors.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2015, 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 /// General type checking tests 5 /// General type checking tests
6 library dev_compiler.test.checker_test; 6 library dev_compiler.test.checker_test;
7 7
8 import 'package:unittest/unittest.dart'; 8 import 'package:unittest/unittest.dart';
9 9
10 import 'package:dev_compiler/src/testing.dart'; 10 import 'package:dev_compiler/src/testing.dart';
11 11
12 import '../test_util.dart'; 12 import '../test_util.dart';
13 13
14 void main() { 14 void main() {
15 configureTest(); 15 configureTest();
16 16
17 test('conversion and dynamic invoke', () { 17 test('conversion and dynamic invoke', () {
18 testChecker({ 18 testChecker({
19 '/main.dart': ''' 19 '/main.dart': '''
20 class A { 20 class A {
21 String x = "hello world"; 21 String x = "hello world";
22
23 void baz1(y) => x + y;
24 static baz2(y) => y + y;
22 } 25 }
23 26
24 void foo(String str) { 27 void foo(String str) {
25 print(str); 28 print(str);
26 } 29 }
27 30
28 void bar(a) { 31 void bar(a) {
29 foo(/*info:DownCast,warning:DynamicInvoke*/a.x); 32 foo(/*info:DownCast,warning:DynamicInvoke*/a.x);
30 } 33 }
31 34
32 void main() => bar(new A()); 35 typedef DynFun(x);
36 typedef StrFun(String x);
37
38 var bar1 = bar;
39
40 void main() {
41 var a = new A();
42 bar(a);
43 (/*warning:DynamicInvoke*/bar1(a));
44 var b = bar;
45 (/*warning:DynamicInvoke*/b(a));
46 var f1 = foo;
47 f1("hello");
48 dynamic f2 = foo;
49 (/*warning:DynamicInvoke*/f2("hello"));
50 DynFun f3 = foo;
51 (/*warning:DynamicInvoke*/f3("hello"));
52 (/*warning:DynamicInvoke*/f3(42));
53 StrFun f4 = foo;
54 f4("hello");
55 a.baz1("hello");
56 var b1 = a.baz1;
57 (/*warning:DynamicInvoke*/b1("hello"));
58 A.baz2("hello");
59 var b2 = A.baz2;
60 (/*warning:DynamicInvoke*/b2("hello"));
33 ''' 61 '''
34 }); 62 });
35 }); 63 });
36 64
37 test('Primitives', () { 65 test('Primitives', () {
38 testChecker({ 66 testChecker({
39 '/main.dart': ''' 67 '/main.dart': '''
40 int /*severe:InvalidVariableDeclaration*/a; 68 int /*severe:InvalidVariableDeclaration*/a;
41 double /*severe:InvalidVariableDeclaration*/b; 69 double /*severe:InvalidVariableDeclaration*/b;
42 num c; 70 num c;
(...skipping 407 matching lines...) Expand 10 before | Expand all | Expand 10 after
450 ''' 478 '''
451 }); 479 });
452 }); 480 });
453 481
454 test('Function typing and subtyping: dynamic', () { 482 test('Function typing and subtyping: dynamic', () {
455 testChecker({ 483 testChecker({
456 '/main.dart': ''' 484 '/main.dart': '''
457 485
458 class A {} 486 class A {}
459 487
460 typedef dynamic Top(A x); // Top of the lattice 488 typedef dynamic Top(dynamic x); // Top of the lattice
461 typedef A Left(A x); // Left branch 489 typedef dynamic Left(A x); // Left branch
462 typedef dynamic Right(dynamic x); // Right branch 490 typedef A Right(dynamic x); // Right branch
463 typedef A Bot(dynamic x); // Bottom of the lattice 491 typedef A Bottom(A x); // Bottom of the lattice
464 492
465 dynamic top(A x) => x; 493 dynamic left(A x) => x;
466 A left(A x) => x; 494 A bot(A x) => x;
467 dynamic right(dynamic x) => x; 495 dynamic top(dynamic x) => x;
468 A bot(dynamic x) => /*info:DownCast*/x; 496 A right(dynamic x) => /*info:DownCast*/x;
469 497
470 void main() { 498 void main() {
471 { 499 {
472 Top f; 500 Top f;
473 f = top; 501 f = top;
474 f = left; 502 f = left;
475 f = right; 503 f = right;
476 f = bot; 504 f = bot;
477 } 505 }
478 { 506 {
479 Left f; 507 Left f;
480 f = /*warning:ClosureWrap*/top; 508 f = /*warning:ClosureWrap*/top;
481 f = left; 509 f = left;
482 f = /*warning:ClosureWrap*/right; 510 f = /*warning:ClosureWrap*/right;
483 f = bot; 511 f = bot;
484 } 512 }
485 { 513 {
486 Right f; 514 Right f;
487 f = /*warning:ClosureWrap*/top; 515 f = /*warning:ClosureWrap*/top;
488 f = /*warning:ClosureWrap*/left; 516 f = /*warning:ClosureWrap*/left;
489 f = right; 517 f = right;
490 f = bot; 518 f = bot;
491 } 519 }
492 { 520 {
493 Bot f; 521 Bottom f;
494 f = /*warning:ClosureWrap*/top; 522 f = /*warning:ClosureWrap*/top;
495 f = /*warning:ClosureWrap*/left; 523 f = /*warning:ClosureWrap*/left;
496 f = /*warning:ClosureWrap*/right; 524 f = /*warning:ClosureWrap*/right;
497 f = bot; 525 f = bot;
498 } 526 }
499 } 527 }
500 ''' 528 '''
501 }); 529 });
502 }); 530 });
503 531
(...skipping 395 matching lines...) Expand 10 before | Expand all | Expand 10 after
899 '/main.dart': ''' 927 '/main.dart': '''
900 typedef T F<T>(T t1, T t2); 928 typedef T F<T>(T t1, T t2);
901 typedef dynamic D(t1, t2); 929 typedef dynamic D(t1, t2);
902 930
903 void main() { 931 void main() {
904 F f1 = (x, y) => x + y; 932 F f1 = (x, y) => x + y;
905 F<int> f2 = /*warning:ClosureWrapLiteral*/(x, y) => x + y; 933 F<int> f2 = /*warning:ClosureWrapLiteral*/(x, y) => x + y;
906 D f3 = (x, y) => x + y; 934 D f3 = (x, y) => x + y;
907 Function f4 = (x, y) => x + y; 935 Function f4 = (x, y) => x + y;
908 f2 = /*warning:ClosureWrap*/f1; 936 f2 = /*warning:ClosureWrap*/f1;
909 f1 = /*warning:ClosureWrapLiteral*/(int x, int y) => x + y; 937 f1 = (int x, int y) => x + y;
910 f2 = /*severe:StaticTypeError*/(int x) => -x; 938 f2 = /*severe:StaticTypeError*/(int x) => -x;
911 } 939 }
912 ''' 940 '''
913 }); 941 });
914 }); 942 });
915 943
916 test('Generic subtyping: invariance', () { 944 test('Generic subtyping: invariance', () {
917 testChecker({ 945 testChecker({
918 '/main.dart': ''' 946 '/main.dart': '''
919 947
(...skipping 676 matching lines...) Expand 10 before | Expand all | Expand 10 after
1596 B f1; 1624 B f1;
1597 B f2; 1625 B f2;
1598 B f3; 1626 B f3;
1599 B f4; 1627 B f4;
1600 } 1628 }
1601 1629
1602 class Child extends Base { 1630 class Child extends Base {
1603 /*severe:InvalidMethodOverride*/A f1; // invalid for getter 1631 /*severe:InvalidMethodOverride*/A f1; // invalid for getter
1604 /*severe:InvalidMethodOverride*/C f2; // invalid for setter 1632 /*severe:InvalidMethodOverride*/C f2; // invalid for setter
1605 var f3; 1633 var f3;
1606 /*severe:InvalidMethodOverride*/dynamic f4; 1634 /*severe:InvalidMethodOverride,severe:InvalidMethodOverride*/dynamic f4;
1607 } 1635 }
1608 ''' 1636 '''
1609 }, inferFromOverrides: true); 1637 }, inferFromOverrides: true);
1610 1638
1611 testChecker({ 1639 testChecker({
1612 '/main.dart': ''' 1640 '/main.dart': '''
1613 class A {} 1641 class A {}
1614 class B extends A {} 1642 class B extends A {}
1615 class C extends B {} 1643 class C extends B {}
1616 1644
1617 class Base { 1645 class Base {
1618 B f1; 1646 B f1;
1619 B f2; 1647 B f2;
1620 B f3; 1648 B f3;
1621 B f4; 1649 B f4;
1622 } 1650 }
1623 1651
1624 class Child extends Base { 1652 class Child extends Base {
1625 /*severe:InvalidMethodOverride*/A f1; // invalid for getter 1653 /*severe:InvalidMethodOverride*/A f1; // invalid for getter
1626 /*severe:InvalidMethodOverride*/C f2; // invalid for setter 1654 /*severe:InvalidMethodOverride*/C f2; // invalid for setter
1627 /*severe:InferableOverride*/var f3; 1655 /*severe:InferableOverride,severe:InvalidMethodOverride*/var f3;
1628 /*severe:InvalidMethodOverride*/dynamic f4; 1656 /*severe:InvalidMethodOverride,severe:InvalidMethodOverride*/dynamic f4;
1629 } 1657 }
1630 ''' 1658 '''
1631 }, inferFromOverrides: false); 1659 }, inferFromOverrides: false);
1632 }); 1660 });
1633 1661
1634 test('getter/getter override', () { 1662 test('getter/getter override', () {
1635 testChecker({ 1663 testChecker({
1636 '/main.dart': ''' 1664 '/main.dart': '''
1637 class A {} 1665 class A {}
1638 class B extends A {} 1666 class B extends A {}
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
1712 void set f1(B value); 1740 void set f1(B value);
1713 void set f2(B value); 1741 void set f2(B value);
1714 void set f3(B value); 1742 void set f3(B value);
1715 void set f4(B value); 1743 void set f4(B value);
1716 void set f5(B value); 1744 void set f5(B value);
1717 } 1745 }
1718 1746
1719 class Child extends Base { 1747 class Child extends Base {
1720 void set f1(A value) {} 1748 void set f1(A value) {}
1721 /*severe:InvalidMethodOverride*/void set f2(C value) {} 1749 /*severe:InvalidMethodOverride*/void set f2(C value) {}
1722 void set f3(value) {} 1750 /*severe:InvalidMethodOverride*/void set f3(value) {}
1723 void set f4(dynamic value) {} 1751 /*severe:InvalidMethodOverride*/void set f4(dynamic value) {}
1724 set f5(B value) {} 1752 set f5(B value) {}
1725 } 1753 }
1726 ''' 1754 '''
1727 }); 1755 });
1728 }); 1756 });
1729 1757
1730 test('field/setter override', () { 1758 test('field/setter override', () {
1731 testChecker({ 1759 testChecker({
1732 '/main.dart': ''' 1760 '/main.dart': '''
1733 class A {} 1761 class A {}
(...skipping 10 matching lines...) Expand all
1744 1772
1745 class Child extends Base { 1773 class Child extends Base {
1746 B get f1 => null; 1774 B get f1 => null;
1747 B get f2 => null; 1775 B get f2 => null;
1748 B get f3 => null; 1776 B get f3 => null;
1749 B get f4 => null; 1777 B get f4 => null;
1750 B get f5 => null; 1778 B get f5 => null;
1751 1779
1752 void set f1(A value) {} 1780 void set f1(A value) {}
1753 /*severe:InvalidMethodOverride*/void set f2(C value) {} 1781 /*severe:InvalidMethodOverride*/void set f2(C value) {}
1754 void set f3(value) {} 1782 /*severe:InvalidMethodOverride*/void set f3(value) {}
1755 void set f4(dynamic value) {} 1783 /*severe:InvalidMethodOverride*/void set f4(dynamic value) {}
1756 set f5(B value) {} 1784 set f5(B value) {}
1757 } 1785 }
1758 ''' 1786 '''
1759 }); 1787 });
1760 }); 1788 });
1761 1789
1762 test('method override', () { 1790 test('method override', () {
1763 testChecker({ 1791 testChecker({
1764 '/main.dart': ''' 1792 '/main.dart': '''
1765 class A {} 1793 class A {}
1766 class B extends A {} 1794 class B extends A {}
1767 class C extends B {} 1795 class C extends B {}
1768 1796
1769 class Base { 1797 class Base {
1770 B m1(B a); 1798 B m1(B a);
1771 B m2(B a); 1799 B m2(B a);
1772 B m3(B a); 1800 B m3(B a);
1773 B m4(B a); 1801 B m4(B a);
1774 B m5(B a); 1802 B m5(B a);
1775 B m6(B a); 1803 B m6(B a);
1776 } 1804 }
1777 1805
1778 class Child extends Base { 1806 class Child extends Base {
1779 /*severe:InvalidMethodOverride*/A m1(A value) {} 1807 /*severe:InvalidMethodOverride*/A m1(A value) {}
1780 /*severe:InvalidMethodOverride*/C m2(C value) {} 1808 /*severe:InvalidMethodOverride*/C m2(C value) {}
1781 /*severe:InvalidMethodOverride*/A m3(C value) {} 1809 /*severe:InvalidMethodOverride*/A m3(C value) {}
1782 C m4(A value) {} 1810 C m4(A value) {}
1783 m5(value) {} 1811 /*severe:InvalidMethodOverride*/m5(value) {}
1784 /*severe:InvalidMethodOverride*/dynamic m6(dynamic value) {} 1812 /*severe:InvalidMethodOverride*/dynamic m6(dynamic value) {}
1785 } 1813 }
1786 ''' 1814 '''
1787 }, inferFromOverrides: true); 1815 }, inferFromOverrides: true);
1788 }); 1816 });
1789 1817
1790 test('binary operators', () { 1818 test('binary operators', () {
1791 testChecker({ 1819 testChecker({
1792 '/main.dart': ''' 1820 '/main.dart': '''
1793 class A { 1821 class A {
(...skipping 413 matching lines...) Expand 10 before | Expand all | Expand 10 after
2207 } 2235 }
2208 2236
2209 class I1 { 2237 class I1 {
2210 m(B a) {} 2238 m(B a) {}
2211 } 2239 }
2212 2240
2213 class T1 /*severe:InvalidMethodOverride*/extends Base 2241 class T1 /*severe:InvalidMethodOverride*/extends Base
2214 implements I1 {} 2242 implements I1 {}
2215 2243
2216 class T2 extends Base implements I1 { 2244 class T2 extends Base implements I1 {
2217 m(a) {} 2245 /*severe:InvalidMethodOverride,severe:InvalidMethodOverride*/m(a ) {}
2218 } 2246 }
2219 2247
2220 class T3 extends Object with /*severe:InvalidMethodOverride*/Base 2248 class T3 extends Object with /*severe:InvalidMethodOverride*/Base
2221 implements I1 {} 2249 implements I1 {}
2222 2250
2223 class T4 extends Object with Base implements I1 { 2251 class T4 extends Object with Base implements I1 {
2224 m(a) {} 2252 /*severe:InvalidMethodOverride,severe:InvalidMethodOverride*/m(a ) {}
2225 } 2253 }
2226 ''' 2254 '''
2227 }); 2255 });
2228 }); 2256 });
2229 2257
2230 group('class override of grand interface', () { 2258 group('class override of grand interface', () {
2231 test('interface of interface of child', () { 2259 test('interface of interface of child', () {
2232 testChecker({ 2260 testChecker({
2233 '/main.dart': ''' 2261 '/main.dart': '''
2234 class A {} 2262 class A {}
(...skipping 484 matching lines...) Expand 10 before | Expand all | Expand 10 after
2719 '/main.dart': ''' 2747 '/main.dart': '''
2720 class A {} 2748 class A {}
2721 class T1 implements A { 2749 class T1 implements A {
2722 /*severe:InferableOverride*/toString() {} 2750 /*severe:InferableOverride*/toString() {}
2723 } 2751 }
2724 ''' 2752 '''
2725 }, inferFromOverrides: false); 2753 }, inferFromOverrides: false);
2726 }); 2754 });
2727 }); 2755 });
2728 } 2756 }
OLDNEW
« no previous file with comments | « lib/src/testing.dart ('k') | test/codegen/expect/dart/_interceptors.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698