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

Side by Side Diff: pkg/analyzer/test/src/task/strong/inferred_type_test.dart

Issue 2524463005: Add tests for the real generic method syntax (Closed)
Patch Set: Created 4 years, 1 month 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 | « no previous file | no next file » | 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 // TODO(jmesserly): this file needs to be refactored, it's a port from 5 // TODO(jmesserly): this file needs to be refactored, it's a port from
6 // package:dev_compiler's tests 6 // package:dev_compiler's tests
7 /// Tests for type inference. 7 /// Tests for type inference.
8 library analyzer.test.src.task.strong.inferred_type_test; 8 library analyzer.test.src.task.strong.inferred_type_test;
9 9
10 import 'package:analyzer/dart/element/element.dart'; 10 import 'package:analyzer/dart/element/element.dart';
(...skipping 1049 matching lines...) Expand 10 before | Expand all | Expand 10 after
1060 Function2<String, String> l4 = /*info:INFERRED_TYPE_CLOSURE*/(x) => x.substr ing(3); 1060 Function2<String, String> l4 = /*info:INFERRED_TYPE_CLOSURE*/(x) => x.substr ing(3);
1061 } 1061 }
1062 } 1062 }
1063 '''); 1063 ''');
1064 } 1064 }
1065 1065
1066 void test_downwardsInferenceOnFunctionOfTUsingTheT() { 1066 void test_downwardsInferenceOnFunctionOfTUsingTheT() {
1067 checkFile(''' 1067 checkFile('''
1068 void main () { 1068 void main () {
1069 { 1069 {
1070 T f<T>(T x) => null;
1071 var v1 = f;
1072 v1 = /*info:INFERRED_TYPE_CLOSURE*/<S>(x) => x;
1073 }
1074 {
1075 List<T> f<T>(T x) => null;
1076 var v2 = f;
1077 v2 = /*info:INFERRED_TYPE_CLOSURE*/<S>(x) => /*info:INFERRED_TYPE_LITERAL*/[ x];
1078 Iterable<int> r = v2(42);
1079 Iterable<String> s = v2('hello');
1080 Iterable<List<int>> t = v2(<int>[]);
1081 Iterable<num> u = v2(42);
1082 Iterable<num> v = v2<num>(42);
1083 }
1084 }
1085 ''');
1086 }
1087
1088 void test_downwardsInferenceOnFunctionOfTUsingTheT_comment() {
1089 checkFile('''
1090 void main () {
1091 {
1070 /*=T*/ f/*<T>*/(/*=T*/ x) => null; 1092 /*=T*/ f/*<T>*/(/*=T*/ x) => null;
1071 var v1 = f; 1093 var v1 = f;
1072 v1 = /*info:INFERRED_TYPE_CLOSURE*//*<S>*/(x) => x; 1094 v1 = /*info:INFERRED_TYPE_CLOSURE*//*<S>*/(x) => x;
1073 } 1095 }
1074 { 1096 {
1075 /*=List<T>*/ f/*<T>*/(/*=T*/ x) => null; 1097 /*=List<T>*/ f/*<T>*/(/*=T*/ x) => null;
1076 var v2 = f; 1098 var v2 = f;
1077 v2 = /*info:INFERRED_TYPE_CLOSURE*//*<S>*/(x) => /*info:INFERRED_TYPE_LITERA L*/[x]; 1099 v2 = /*info:INFERRED_TYPE_CLOSURE*//*<S>*/(x) => /*info:INFERRED_TYPE_LITERA L*/[x];
1078 Iterable<int> r = v2(42); 1100 Iterable<int> r = v2(42);
1079 Iterable<String> s = v2('hello'); 1101 Iterable<String> s = v2('hello');
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
1143 /*info:INFERRED_TYPE_ALLOCATION*/new F4(a: /*info:INFERRED_TYPE_LITERAL*/[/*in fo:INFERRED_TYPE_LITERAL*/["hello"], 1165 /*info:INFERRED_TYPE_ALLOCATION*/new F4(a: /*info:INFERRED_TYPE_LITERAL*/[/*in fo:INFERRED_TYPE_LITERAL*/["hello"],
1144 /*info:INFERRED_TYPE_LITERAL*/[3]]); 1166 /*info:INFERRED_TYPE_LITERAL*/[3]]);
1145 } 1167 }
1146 '''); 1168 ''');
1147 } 1169 }
1148 1170
1149 void test_downwardsInferenceOnGenericFunctionExpressions() { 1171 void test_downwardsInferenceOnGenericFunctionExpressions() {
1150 checkFile(''' 1172 checkFile('''
1151 void main () { 1173 void main () {
1152 { 1174 {
1175 String f<S>(int x) => null;
1176 var v = f;
1177 v = /*info:INFERRED_TYPE_CLOSURE*/<T>(int x) => null;
1178 v = <T>(int x) => "hello";
1179 v = /*error:INVALID_ASSIGNMENT*/<T>(String x) => "hello";
1180 v = /*error:INVALID_ASSIGNMENT*/<T>(int x) => 3;
1181 v = /*info:INFERRED_TYPE_CLOSURE*/<T>(int x) {return /*error:RETURN_OF_INVAL ID_TYPE*/3;};
1182 }
1183 {
1184 String f<S>(int x) => null;
1185 var v = f;
1186 v = /*info:INFERRED_TYPE_CLOSURE, info:INFERRED_TYPE_CLOSURE*/<T>(x) => null ;
1187 v = /*info:INFERRED_TYPE_CLOSURE*/<T>(x) => "hello";
1188 v = /*info:INFERRED_TYPE_CLOSURE, error:INVALID_ASSIGNMENT*/<T>(x) => 3;
1189 v = /*info:INFERRED_TYPE_CLOSURE, info:INFERRED_TYPE_CLOSURE*/<T>(x) {return /*error:RETURN_OF_INVALID_TYPE*/3;};
1190 v = /*info:INFERRED_TYPE_CLOSURE, info:INFERRED_TYPE_CLOSURE*/<T>(x) {return /*error:RETURN_OF_INVALID_TYPE*/x;};
1191 }
1192 {
1193 List<String> f<S>(int x) => null;
1194 var v = f;
1195 v = /*info:INFERRED_TYPE_CLOSURE*/<T>(int x) => null;
1196 v = <T>(int x) => /*info:INFERRED_TYPE_LITERAL*/["hello"];
1197 v = /*error:INVALID_ASSIGNMENT*/<T>(String x) => /*info:INFERRED_TYPE_LITERA L*/["hello"];
1198 v = <T>(int x) => /*info:INFERRED_TYPE_LITERAL,error:COULD_NOT_INFER*/[/*err or:LIST_ELEMENT_TYPE_NOT_ASSIGNABLE*/3];
1199 v = /*info:INFERRED_TYPE_CLOSURE*/<T>(int x) {return /*info:INFERRED_TYPE_LI TERAL,error:COULD_NOT_INFER*/[/*error:LIST_ELEMENT_TYPE_NOT_ASSIGNABLE*/3];};
1200 }
1201 {
1202 int int2int<S>(int x) => null;
1203 String int2String<T>(int x) => null;
1204 String string2String<T>(String x) => null;
1205 var x = int2int;
1206 x = /*info:INFERRED_TYPE_CLOSURE*/<T>(x) => x;
1207 x = /*info:INFERRED_TYPE_CLOSURE*/<T>(x) => x+1;
1208 var y = int2String;
1209 y = /*info:INFERRED_TYPE_CLOSURE, error:INVALID_ASSIGNMENT*/<T>(x) => x;
1210 y = /*info:INFERRED_TYPE_CLOSURE, info:INFERRED_TYPE_CLOSURE*/<T>(x) => /*in fo:DYNAMIC_INVOKE, info:DYNAMIC_CAST*/x.substring(3);
1211 var z = string2String;
1212 z = /*info:INFERRED_TYPE_CLOSURE*/<T>(x) => x.substring(3);
1213 }
1214 }
1215 ''');
1216 }
1217
1218 void test_downwardsInferenceOnGenericFunctionExpressions_comment() {
1219 checkFile('''
1220 void main () {
1221 {
1153 String f/*<S>*/(int x) => null; 1222 String f/*<S>*/(int x) => null;
1154 var v = f; 1223 var v = f;
1155 v = /*info:INFERRED_TYPE_CLOSURE*//*<T>*/(int x) => null; 1224 v = /*info:INFERRED_TYPE_CLOSURE*//*<T>*/(int x) => null;
1156 v = /*<T>*/(int x) => "hello"; 1225 v = /*<T>*/(int x) => "hello";
1157 v = /*error:INVALID_ASSIGNMENT*//*<T>*/(String x) => "hello"; 1226 v = /*error:INVALID_ASSIGNMENT*//*<T>*/(String x) => "hello";
1158 v = /*error:INVALID_ASSIGNMENT*//*<T>*/(int x) => 3; 1227 v = /*error:INVALID_ASSIGNMENT*//*<T>*/(int x) => 3;
1159 v = /*info:INFERRED_TYPE_CLOSURE*//*<T>*/(int x) {return /*error:RETURN_OF_I NVALID_TYPE*/3;}; 1228 v = /*info:INFERRED_TYPE_CLOSURE*//*<T>*/(int x) {return /*error:RETURN_OF_I NVALID_TYPE*/3;};
1160 } 1229 }
1161 { 1230 {
1162 String f/*<S>*/(int x) => null; 1231 String f/*<S>*/(int x) => null;
(...skipping 367 matching lines...) Expand 10 before | Expand all | Expand 10 after
1530 expect(x.type.toString(), 'int'); 1599 expect(x.type.toString(), 'int');
1531 } 1600 }
1532 1601
1533 void test_futureThen() { 1602 void test_futureThen() {
1534 String build({String declared, String downwards, String upwards}) => ''' 1603 String build({String declared, String downwards, String upwards}) => '''
1535 import 'dart:async'; 1604 import 'dart:async';
1536 class MyFuture<T> implements Future<T> { 1605 class MyFuture<T> implements Future<T> {
1537 MyFuture() {} 1606 MyFuture() {}
1538 MyFuture.value(T x) {} 1607 MyFuture.value(T x) {}
1539 dynamic noSuchMethod(invocation); 1608 dynamic noSuchMethod(invocation);
1609 MyFuture<S> then<S>(dynamic f(T x), {Function onError}) => null;
1610 }
1611
1612 void main() {
1613 $declared f;
1614 $downwards<int> t1 = f.then((_) async => await new $upwards<int>.value(3));
1615 $downwards<int> t2 = f.then(/*info:INFERRED_TYPE_CLOSURE*/(_) async {
1616 return await new $upwards<int>.value(3);});
1617 $downwards<int> t3 = f.then((_) async => 3);
1618 $downwards<int> t4 = f.then(/*info:INFERRED_TYPE_CLOSURE*/(_) async {
1619 return 3;});
1620 $downwards<int> t5 = f.then((_) => new $upwards<int>.value(3));
1621 $downwards<int> t6 = f.then(/*info:INFERRED_TYPE_CLOSURE*/(_) {return new $upw ards<int>.value(3);});
1622 $downwards<int> t7 = f.then((_) async => new $upwards<int>.value(3));
1623 $downwards<int> t8 = f.then(/*info:INFERRED_TYPE_CLOSURE*/(_) async {
1624 return new $upwards<int>.value(3);});
1625 }
1626 ''';
1627
1628 checkFile(
1629 build(declared: "MyFuture", downwards: "Future", upwards: "Future"));
1630 checkFile(
1631 build(declared: "MyFuture", downwards: "Future", upwards: "MyFuture"));
1632 checkFile(
1633 build(declared: "MyFuture", downwards: "MyFuture", upwards: "Future"));
1634 checkFile(build(
1635 declared: "MyFuture", downwards: "MyFuture", upwards: "MyFuture"));
1636 checkFile(
1637 build(declared: "Future", downwards: "Future", upwards: "MyFuture"));
1638 checkFile(
1639 build(declared: "Future", downwards: "Future", upwards: "Future"));
1640 }
1641
1642 void test_futureThen_comment() {
1643 String build({String declared, String downwards, String upwards}) => '''
1644 import 'dart:async';
1645 class MyFuture<T> implements Future<T> {
1646 MyFuture() {}
1647 MyFuture.value(T x) {}
1648 dynamic noSuchMethod(invocation);
1540 MyFuture/*<S>*/ then/*<S>*/(dynamic f(T x), {Function onError}) => null; 1649 MyFuture/*<S>*/ then/*<S>*/(dynamic f(T x), {Function onError}) => null;
1541 } 1650 }
1542 1651
1543 void main() { 1652 void main() {
1544 $declared f; 1653 $declared f;
1545 $downwards<int> t1 = f.then((_) async => await new $upwards<int>.value(3)); 1654 $downwards<int> t1 = f.then((_) async => await new $upwards<int>.value(3));
1546 $downwards<int> t2 = f.then(/*info:INFERRED_TYPE_CLOSURE*/(_) async { 1655 $downwards<int> t2 = f.then(/*info:INFERRED_TYPE_CLOSURE*/(_) async {
1547 return await new $upwards<int>.value(3);}); 1656 return await new $upwards<int>.value(3);});
1548 $downwards<int> t3 = f.then((_) async => 3); 1657 $downwards<int> t3 = f.then((_) async => 3);
1549 $downwards<int> t4 = f.then(/*info:INFERRED_TYPE_CLOSURE*/(_) async { 1658 $downwards<int> t4 = f.then(/*info:INFERRED_TYPE_CLOSURE*/(_) async {
(...skipping 20 matching lines...) Expand all
1570 build(declared: "Future", downwards: "Future", upwards: "Future")); 1679 build(declared: "Future", downwards: "Future", upwards: "Future"));
1571 } 1680 }
1572 1681
1573 void test_futureThen_conditional() { 1682 void test_futureThen_conditional() {
1574 String build({String declared, String downwards, String upwards}) => ''' 1683 String build({String declared, String downwards, String upwards}) => '''
1575 import 'dart:async'; 1684 import 'dart:async';
1576 class MyFuture<T> implements Future<T> { 1685 class MyFuture<T> implements Future<T> {
1577 MyFuture() {} 1686 MyFuture() {}
1578 MyFuture.value(T x) {} 1687 MyFuture.value(T x) {}
1579 dynamic noSuchMethod(invocation); 1688 dynamic noSuchMethod(invocation);
1689 MyFuture<S> then<S>(dynamic f(T x), {Function onError}) => null;
1690 }
1691
1692 void main() {
1693 $declared<bool> f;
1694 $downwards<int> t1 = f.then(/*info:INFERRED_TYPE_CLOSURE*/
1695 (x) async => x ? 2 : await new $upwards<int>.value(3));
1696 $downwards<int> t2 = f.then(/*info:INFERRED_TYPE_CLOSURE,info:INFERRED_TYPE_CL OSURE*/(x) async { // TODO(leafp): Why the duplicate here?
1697 return await x ? 2 : new $upwards<int>.value(3);});
1698 $downwards<int> t5 = f.then(/*info:INFERRED_TYPE_CLOSURE*/
1699 (x) => x ? 2 : new $upwards<int>.value(3));
1700 $downwards<int> t6 = f.then(/*info:INFERRED_TYPE_CLOSURE*/
1701 (x) {return x ? 2 : new $upwards<int>.value(3);});
1702 }
1703 ''';
1704 checkFile(
1705 build(declared: "MyFuture", downwards: "Future", upwards: "Future"));
1706 checkFile(
1707 build(declared: "MyFuture", downwards: "Future", upwards: "MyFuture"));
1708 checkFile(
1709 build(declared: "MyFuture", downwards: "MyFuture", upwards: "Future"));
1710 checkFile(build(
1711 declared: "MyFuture", downwards: "MyFuture", upwards: "MyFuture"));
1712 checkFile(
1713 build(declared: "Future", downwards: "Future", upwards: "MyFuture"));
1714 checkFile(
1715 build(declared: "Future", downwards: "Future", upwards: "Future"));
1716 }
1717
1718 void test_futureThen_conditional_comment() {
1719 String build({String declared, String downwards, String upwards}) => '''
1720 import 'dart:async';
1721 class MyFuture<T> implements Future<T> {
1722 MyFuture() {}
1723 MyFuture.value(T x) {}
1724 dynamic noSuchMethod(invocation);
1580 MyFuture/*<S>*/ then/*<S>*/(dynamic f(T x), {Function onError}) => null; 1725 MyFuture/*<S>*/ then/*<S>*/(dynamic f(T x), {Function onError}) => null;
1581 } 1726 }
1582 1727
1583 void main() { 1728 void main() {
1584 $declared<bool> f; 1729 $declared<bool> f;
1585 $downwards<int> t1 = f.then(/*info:INFERRED_TYPE_CLOSURE*/ 1730 $downwards<int> t1 = f.then(/*info:INFERRED_TYPE_CLOSURE*/
1586 (x) async => x ? 2 : await new $upwards<int>.value(3)); 1731 (x) async => x ? 2 : await new $upwards<int>.value(3));
1587 $downwards<int> t2 = f.then(/*info:INFERRED_TYPE_CLOSURE,info:INFERRED_TYPE_CL OSURE*/(x) async { // TODO(leafp): Why the duplicate here? 1732 $downwards<int> t2 = f.then(/*info:INFERRED_TYPE_CLOSURE,info:INFERRED_TYPE_CL OSURE*/(x) async { // TODO(leafp): Why the duplicate here?
1588 return await x ? 2 : new $upwards<int>.value(3);}); 1733 return await x ? 2 : new $upwards<int>.value(3);});
1589 $downwards<int> t5 = f.then(/*info:INFERRED_TYPE_CLOSURE*/ 1734 $downwards<int> t5 = f.then(/*info:INFERRED_TYPE_CLOSURE*/
(...skipping 28 matching lines...) Expand all
1618 b = f.then(/*info:INFERRED_TYPE_CLOSURE*/(x) => /*info:INFERRED_TYPE_LITERAL*/ []); 1763 b = f.then(/*info:INFERRED_TYPE_CLOSURE*/(x) => /*info:INFERRED_TYPE_LITERAL*/ []);
1619 } 1764 }
1620 '''); 1765 ''');
1621 } 1766 }
1622 1767
1623 void test_futureThen_explicitFuture() { 1768 void test_futureThen_explicitFuture() {
1624 checkFile(r''' 1769 checkFile(r'''
1625 import "dart:async"; 1770 import "dart:async";
1626 main() { 1771 main() {
1627 Future<int> f; 1772 Future<int> f;
1773 var x = f.then<Future<List<int>>>(/*info:INFERRED_TYPE_CLOSURE*/(x) => /*info: INFERRED_TYPE_LITERAL*/[]);
1774 Future<List<int>> y = x;
1775 }
1776 ''');
1777 }
1778
1779 void test_futureThen_explicitFuture_comment() {
1780 checkFile(r'''
1781 import "dart:async";
1782 main() {
1783 Future<int> f;
1628 var x = f.then/*<Future<List<int>>>*/(/*info:INFERRED_TYPE_CLOSURE*/(x) => /*i nfo:INFERRED_TYPE_LITERAL*/[]); 1784 var x = f.then/*<Future<List<int>>>*/(/*info:INFERRED_TYPE_CLOSURE*/(x) => /*i nfo:INFERRED_TYPE_LITERAL*/[]);
1629 Future<List<int>> y = x; 1785 Future<List<int>> y = x;
1630 } 1786 }
1631 '''); 1787 ''');
1632 } 1788 }
1633 1789
1634 void test_futureThen_upwards() { 1790 void test_futureThen_upwards() {
1635 // Regression test for https://github.com/dart-lang/sdk/issues/27088. 1791 // Regression test for https://github.com/dart-lang/sdk/issues/27088.
1636 String build({String declared, String downwards, String upwards}) => ''' 1792 String build({String declared, String downwards, String upwards}) => '''
1637 import 'dart:async'; 1793 import 'dart:async';
1638 class MyFuture<T> implements Future<T> { 1794 class MyFuture<T> implements Future<T> {
1639 MyFuture() {} 1795 MyFuture() {}
1640 MyFuture.value(T x) {} 1796 MyFuture.value(T x) {}
1641 dynamic noSuchMethod(invocation); 1797 dynamic noSuchMethod(invocation);
1798 MyFuture<S> then<S>(dynamic f(T x), {Function onError}) => null;
1799 }
1800
1801 void main() {
1802 var f = foo().then((_) => 2.3);
1803 $downwards<int> f2 = /*error:INVALID_ASSIGNMENT*/f;
1804
1805 // The unnecessary cast is to illustrate that we inferred <double> for
1806 // the generic type args, even though we had a return type context.
1807 $downwards<num> f3 = /*info:UNNECESSARY_CAST*/foo().then(
1808 (_) => 2.3) as $upwards<double>;
1809 }
1810 $declared foo() => new $declared<int>.value(1);
1811 ''';
1812 checkFile(
1813 build(declared: "MyFuture", downwards: "Future", upwards: "Future"));
1814 checkFile(build(
1815 declared: "MyFuture", downwards: "MyFuture", upwards: "MyFuture"));
1816 checkFile(
1817 build(declared: "Future", downwards: "Future", upwards: "Future"));
1818 }
1819
1820 void test_futureThen_upwards_comment() {
1821 // Regression test for https://github.com/dart-lang/sdk/issues/27088.
1822 String build({String declared, String downwards, String upwards}) => '''
1823 import 'dart:async';
1824 class MyFuture<T> implements Future<T> {
1825 MyFuture() {}
1826 MyFuture.value(T x) {}
1827 dynamic noSuchMethod(invocation);
1642 MyFuture/*<S>*/ then/*<S>*/(dynamic f(T x), {Function onError}) => null; 1828 MyFuture/*<S>*/ then/*<S>*/(dynamic f(T x), {Function onError}) => null;
1643 } 1829 }
1644 1830
1645 void main() { 1831 void main() {
1646 var f = foo().then((_) => 2.3); 1832 var f = foo().then((_) => 2.3);
1647 $downwards<int> f2 = /*error:INVALID_ASSIGNMENT*/f; 1833 $downwards<int> f2 = /*error:INVALID_ASSIGNMENT*/f;
1648 1834
1649 // The unnecessary cast is to illustrate that we inferred <double> for 1835 // The unnecessary cast is to illustrate that we inferred <double> for
1650 // the generic type args, even though we had a return type context. 1836 // the generic type args, even though we had a return type context.
1651 $downwards<num> f3 = /*info:UNNECESSARY_CAST*/foo().then( 1837 $downwards<num> f3 = /*info:UNNECESSARY_CAST*/foo().then(
(...skipping 23 matching lines...) Expand all
1675 '''); 1861 ''');
1676 } 1862 }
1677 1863
1678 void test_futureUnion_asyncConditional() { 1864 void test_futureUnion_asyncConditional() {
1679 String build({String declared, String downwards, String upwards}) => ''' 1865 String build({String declared, String downwards, String upwards}) => '''
1680 import 'dart:async'; 1866 import 'dart:async';
1681 class MyFuture<T> implements Future<T> { 1867 class MyFuture<T> implements Future<T> {
1682 MyFuture() {} 1868 MyFuture() {}
1683 MyFuture.value(T x) {} 1869 MyFuture.value(T x) {}
1684 dynamic noSuchMethod(invocation); 1870 dynamic noSuchMethod(invocation);
1871 MyFuture<S> then<S>(dynamic f(T x), {Function onError}) => null;
1872 }
1873
1874 $downwards<int> g1(bool x) async {
1875 return x ? 42 : /*info:INFERRED_TYPE_ALLOCATION*/new $upwards.value(42); }
1876 $downwards<int> g2(bool x) async =>
1877 x ? 42 : /*info:INFERRED_TYPE_ALLOCATION*/new $upwards.value(42);
1878 $downwards<int> g3(bool x) async {
1879 var y = x ? 42 : /*info:INFERRED_TYPE_ALLOCATION*/new $upwards.value(42);
1880 return y;
1881 }
1882 ''';
1883 checkFile(build(downwards: "Future", upwards: "Future"));
1884 checkFile(build(downwards: "Future", upwards: "MyFuture"));
1885 }
1886
1887 void test_futureUnion_asyncConditional_comment() {
1888 String build({String declared, String downwards, String upwards}) => '''
1889 import 'dart:async';
1890 class MyFuture<T> implements Future<T> {
1891 MyFuture() {}
1892 MyFuture.value(T x) {}
1893 dynamic noSuchMethod(invocation);
1685 MyFuture/*<S>*/ then/*<S>*/(dynamic f(T x), {Function onError}) => null; 1894 MyFuture/*<S>*/ then/*<S>*/(dynamic f(T x), {Function onError}) => null;
1686 } 1895 }
1687 1896
1688 $downwards<int> g1(bool x) async { 1897 $downwards<int> g1(bool x) async {
1689 return x ? 42 : /*info:INFERRED_TYPE_ALLOCATION*/new $upwards.value(42); } 1898 return x ? 42 : /*info:INFERRED_TYPE_ALLOCATION*/new $upwards.value(42); }
1690 $downwards<int> g2(bool x) async => 1899 $downwards<int> g2(bool x) async =>
1691 x ? 42 : /*info:INFERRED_TYPE_ALLOCATION*/new $upwards.value(42); 1900 x ? 42 : /*info:INFERRED_TYPE_ALLOCATION*/new $upwards.value(42);
1692 $downwards<int> g3(bool x) async { 1901 $downwards<int> g3(bool x) async {
1693 var y = x ? 42 : /*info:INFERRED_TYPE_ALLOCATION*/new $upwards.value(42); 1902 var y = x ? 42 : /*info:INFERRED_TYPE_ALLOCATION*/new $upwards.value(42);
1694 return y; 1903 return y;
1695 } 1904 }
1696 '''; 1905 ''';
1697 checkFile(build(downwards: "Future", upwards: "Future")); 1906 checkFile(build(downwards: "Future", upwards: "Future"));
1698 checkFile(build(downwards: "Future", upwards: "MyFuture")); 1907 checkFile(build(downwards: "Future", upwards: "MyFuture"));
1699 } 1908 }
1700 1909
1701 void test_futureUnion_downwards() { 1910 void test_futureUnion_downwards() {
1702 String build({String declared, String downwards, String upwards}) { 1911 String build({String declared, String downwards, String upwards}) {
1703 // TODO(leafp): The use of matchTypes in visitInstanceCreationExpression 1912 // TODO(leafp): The use of matchTypes in visitInstanceCreationExpression
1704 // in the resolver visitor isn't powerful enough to catch this for the 1913 // in the resolver visitor isn't powerful enough to catch this for the
1705 // subclass. See the TODO there. 1914 // subclass. See the TODO there.
1706 var allocInfo = 1915 var allocInfo =
1707 (upwards == "Future") ? "/*info:INFERRED_TYPE_ALLOCATION*/" : ""; 1916 (upwards == "Future") ? "/*info:INFERRED_TYPE_ALLOCATION*/" : "";
1708 return ''' 1917 return '''
1709 import 'dart:async'; 1918 import 'dart:async';
1710 class MyFuture<T> implements Future<T> { 1919 class MyFuture<T> implements Future<T> {
1711 MyFuture() {} 1920 MyFuture() {}
1712 MyFuture.value([T x]) {} 1921 MyFuture.value([T x]) {}
1713 dynamic noSuchMethod(invocation); 1922 dynamic noSuchMethod(invocation);
1923 MyFuture<S> then<S>(dynamic f(T x), {Function onError}) => null;
1924 }
1925
1926 $declared f;
1927 // Instantiates Future<int>
1928 $downwards<int> t1 = f.then((_) =>
1929 ${allocInfo}new /*error:COULD_NOT_INFER*/$upwards.value(
1930 /*error:ARGUMENT_TYPE_NOT_ASSIGNABLE*/'hi'));
1931
1932 // Instantiates List<int>
1933 $downwards<List<int>> t2 = f.then((_) => /*info:INFERRED_TYPE_LITERAL*/[3]);
1934 $downwards<List<int>> g2() async { return /*info:INFERRED_TYPE_LITERAL*/[3]; }
1935 $downwards<List<int>> g3() async {
1936 return /*info:INFERRED_TYPE_ALLOCATION*/new $upwards.value(
1937 /*info:INFERRED_TYPE_LITERAL*/[3]); }
1938 ''';
1939 }
1940
1941 ;
1942 checkFile(
1943 build(declared: "MyFuture", downwards: "Future", upwards: "Future"));
1944 checkFile(
1945 build(declared: "MyFuture", downwards: "Future", upwards: "MyFuture"));
1946 checkFile(
1947 build(declared: "Future", downwards: "Future", upwards: "Future"));
1948 checkFile(
1949 build(declared: "Future", downwards: "Future", upwards: "MyFuture"));
1950 }
1951
1952 void test_futureUnion_downwards_comment() {
1953 String build({String declared, String downwards, String upwards}) {
1954 // TODO(leafp): The use of matchTypes in visitInstanceCreationExpression
1955 // in the resolver visitor isn't powerful enough to catch this for the
1956 // subclass. See the TODO there.
1957 var allocInfo =
1958 (upwards == "Future") ? "/*info:INFERRED_TYPE_ALLOCATION*/" : "";
1959 return '''
1960 import 'dart:async';
1961 class MyFuture<T> implements Future<T> {
1962 MyFuture() {}
1963 MyFuture.value([T x]) {}
1964 dynamic noSuchMethod(invocation);
1714 MyFuture/*<S>*/ then/*<S>*/(dynamic f(T x), {Function onError}) => null; 1965 MyFuture/*<S>*/ then/*<S>*/(dynamic f(T x), {Function onError}) => null;
1715 } 1966 }
1716 1967
1717 $declared f; 1968 $declared f;
1718 // Instantiates Future<int> 1969 // Instantiates Future<int>
1719 $downwards<int> t1 = f.then((_) => 1970 $downwards<int> t1 = f.then((_) =>
1720 ${allocInfo}new /*error:COULD_NOT_INFER*/$upwards.value( 1971 ${allocInfo}new /*error:COULD_NOT_INFER*/$upwards.value(
1721 /*error:ARGUMENT_TYPE_NOT_ASSIGNABLE*/'hi')); 1972 /*error:ARGUMENT_TYPE_NOT_ASSIGNABLE*/'hi'));
1722 1973
1723 // Instantiates List<int> 1974 // Instantiates List<int>
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
1756 2007
1757 class A {} 2008 class A {}
1758 '''); 2009 ''');
1759 } 2010 }
1760 2011
1761 void test_futureUnion_downwardsGenericMethodWithGenericReturn() { 2012 void test_futureUnion_downwardsGenericMethodWithGenericReturn() {
1762 // Regression test for https://github.com/dart-lang/sdk/issues/27284 2013 // Regression test for https://github.com/dart-lang/sdk/issues/27284
1763 checkFile(r''' 2014 checkFile(r'''
1764 import 'dart:async'; 2015 import 'dart:async';
1765 2016
2017 T id<T>(T x) => x;
2018
2019 main() async {
2020 Future<String> f;
2021 String s = await id(f);
2022 }
2023 ''');
2024 }
2025
2026 void test_futureUnion_downwardsGenericMethodWithGenericReturn_comment() {
2027 // Regression test for https://github.com/dart-lang/sdk/issues/27284
2028 checkFile(r'''
2029 import 'dart:async';
2030
1766 /*=T*/ id/*<T>*/(/*=T*/ x) => x; 2031 /*=T*/ id/*<T>*/(/*=T*/ x) => x;
1767 2032
1768 main() async { 2033 main() async {
1769 Future<String> f; 2034 Future<String> f;
1770 String s = await id(f); 2035 String s = await id(f);
1771 } 2036 }
1772 '''); 2037 ''');
1773 } 2038 }
1774 2039
1775 void test_futureUnion_upwardsGenericMethods() { 2040 void test_futureUnion_upwardsGenericMethods() {
(...skipping 15 matching lines...) Expand all
1791 class B extends A {} 2056 class B extends A {}
1792 class C extends A {} 2057 class C extends A {}
1793 '''); 2058 ''');
1794 } 2059 }
1795 2060
1796 void test_genericFunctions_returnTypedef() { 2061 void test_genericFunctions_returnTypedef() {
1797 checkFile(r''' 2062 checkFile(r'''
1798 typedef void ToValue<T>(T value); 2063 typedef void ToValue<T>(T value);
1799 2064
1800 main() { 2065 main() {
2066 ToValue<T> f<T>(T x) => null;
2067 var x = f<int>(42);
2068 var y = f(42);
2069 ToValue<int> takesInt = x;
2070 takesInt = y;
2071 }
2072 ''');
2073 }
2074
2075 void test_genericFunctions_returnTypedef_comment() {
2076 checkFile(r'''
2077 typedef void ToValue<T>(T value);
2078
2079 main() {
1801 ToValue/*<T>*/ f/*<T>*/(dynamic /*=T*/ x) => null; 2080 ToValue/*<T>*/ f/*<T>*/(dynamic /*=T*/ x) => null;
1802 var x = f/*<int>*/(42); 2081 var x = f/*<int>*/(42);
1803 var y = f(42); 2082 var y = f(42);
1804 ToValue<int> takesInt = x; 2083 ToValue<int> takesInt = x;
1805 takesInt = y; 2084 takesInt = y;
1806 } 2085 }
1807 '''); 2086 ''');
1808 } 2087 }
1809 2088
1810 void test_genericMethods_basicDownwardInference() { 2089 void test_genericMethods_basicDownwardInference() {
1811 checkFile(r''' 2090 checkFile(r'''
2091 T f<S, T>(S s) => null;
2092 main() {
2093 String x = f(42);
2094 String y = (f)(42);
2095 }
2096 ''');
2097 }
2098
2099 void test_genericMethods_basicDownwardInference_comment() {
2100 checkFile(r'''
1812 /*=T*/ f/*<S, T>*/(/*=S*/ s) => null; 2101 /*=T*/ f/*<S, T>*/(/*=S*/ s) => null;
1813 main() { 2102 main() {
1814 String x = f(42); 2103 String x = f(42);
1815 String y = (f)(42); 2104 String y = (f)(42);
1816 } 2105 }
1817 '''); 2106 ''');
1818 } 2107 }
1819 2108
1820 void test_genericMethods_correctlyRecognizeGenericUpperBound() { 2109 void test_genericMethods_correctlyRecognizeGenericUpperBound() {
1821 // Regression test for https://github.com/dart-lang/sdk/issues/25740. 2110 // Regression test for https://github.com/dart-lang/sdk/issues/25740.
1822 checkFile(r''' 2111 checkFile(r'''
1823 class Foo<T extends Pattern> { 2112 class Foo<T extends Pattern> {
2113 U method<U extends T>(U u) => u;
2114 }
2115 main() {
2116 String s;
2117 var a = new Foo().method<String>("str");
2118 s = a;
2119 new Foo();
2120
2121 var b = new Foo<String>().method("str");
2122 s = b;
2123 var c = new Foo().method("str");
2124 s = c;
2125
2126 new Foo<String>()./*error:COULD_NOT_INFER*/method(/*error:ARGUMENT_TYPE_NOT_AS SIGNABLE*/42);
2127 }
2128 ''');
2129 }
2130
2131 void test_genericMethods_correctlyRecognizeGenericUpperBound_comment() {
2132 // Regression test for https://github.com/dart-lang/sdk/issues/25740.
2133 checkFile(r'''
2134 class Foo<T extends Pattern> {
1824 /*=U*/ method/*<U extends T>*/(/*=U*/ u) => u; 2135 /*=U*/ method/*<U extends T>*/(/*=U*/ u) => u;
1825 } 2136 }
1826 main() { 2137 main() {
1827 String s; 2138 String s;
1828 var a = new Foo().method/*<String>*/("str"); 2139 var a = new Foo().method/*<String>*/("str");
1829 s = a; 2140 s = a;
1830 new Foo(); 2141 new Foo();
1831 2142
1832 var b = new Foo<String>().method("str"); 2143 var b = new Foo<String>().method("str");
1833 s = b; 2144 s = b;
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
1870 /*error:COULD_NOT_INFER*/min( 2181 /*error:COULD_NOT_INFER*/min(
1871 /*error:ARGUMENT_TYPE_NOT_ASSIGNABLE*/"hi", 2182 /*error:ARGUMENT_TYPE_NOT_ASSIGNABLE*/"hi",
1872 /*error:ARGUMENT_TYPE_NOT_ASSIGNABLE*/"there")); 2183 /*error:ARGUMENT_TYPE_NOT_ASSIGNABLE*/"there"));
1873 } 2184 }
1874 '''); 2185 ''');
1875 } 2186 }
1876 2187
1877 void test_genericMethods_doNotInferInvalidOverrideOfGenericMethod() { 2188 void test_genericMethods_doNotInferInvalidOverrideOfGenericMethod() {
1878 checkFile(''' 2189 checkFile('''
1879 class C { 2190 class C {
2191 T m<T>(T x) => x;
2192 }
2193 class D extends C {
2194 /*error:INVALID_METHOD_OVERRIDE*/m(x) => x;
2195 }
2196 main() {
2197 int y = /*info:DYNAMIC_CAST*/new D()./*error:WRONG_NUMBER_OF_TYPE_ARGUMENTS_ME THOD*/m<int>(42);
2198 print(y);
2199 }
2200 ''');
2201 }
2202
2203 void test_genericMethods_doNotInferInvalidOverrideOfGenericMethod_comment() {
2204 checkFile('''
2205 class C {
1880 /*=T*/ m/*<T>*/(/*=T*/ x) => x; 2206 /*=T*/ m/*<T>*/(/*=T*/ x) => x;
1881 } 2207 }
1882 class D extends C { 2208 class D extends C {
1883 /*error:INVALID_METHOD_OVERRIDE*/m(x) => x; 2209 /*error:INVALID_METHOD_OVERRIDE*/m(x) => x;
1884 } 2210 }
1885 main() { 2211 main() {
1886 int y = /*info:DYNAMIC_CAST*/new D()./*error:WRONG_NUMBER_OF_TYPE_ARGUMENTS_ME THOD*/m/*<int>*/(42); 2212 int y = /*info:DYNAMIC_CAST*/new D()./*error:WRONG_NUMBER_OF_TYPE_ARGUMENTS_ME THOD*/m/*<int>*/(42);
1887 print(y); 2213 print(y);
1888 } 2214 }
1889 '''); 2215 ''');
1890 } 2216 }
1891 2217
1892 void test_genericMethods_downwardsInferenceAffectsArguments() { 2218 void test_genericMethods_downwardsInferenceAffectsArguments() {
1893 checkFile(r''' 2219 checkFile(r'''
2220 T f<T>(List<T> s) => null;
2221 main() {
2222 String x = f(/*info:INFERRED_TYPE_LITERAL*/['hi']);
2223 String y = f(/*info:INFERRED_TYPE_LITERAL,error:COULD_NOT_INFER*/[/*error:LIST _ELEMENT_TYPE_NOT_ASSIGNABLE*/42]);
2224 }
2225 ''');
2226 }
2227
2228 void test_genericMethods_downwardsInferenceAffectsArguments_comment() {
2229 checkFile(r'''
1894 /*=T*/ f/*<T>*/(List/*<T>*/ s) => null; 2230 /*=T*/ f/*<T>*/(List/*<T>*/ s) => null;
1895 main() { 2231 main() {
1896 String x = f(/*info:INFERRED_TYPE_LITERAL*/['hi']); 2232 String x = f(/*info:INFERRED_TYPE_LITERAL*/['hi']);
1897 String y = f(/*info:INFERRED_TYPE_LITERAL,error:COULD_NOT_INFER*/[/*error:LIST _ELEMENT_TYPE_NOT_ASSIGNABLE*/42]); 2233 String y = f(/*info:INFERRED_TYPE_LITERAL,error:COULD_NOT_INFER*/[/*error:LIST _ELEMENT_TYPE_NOT_ASSIGNABLE*/42]);
1898 } 2234 }
1899 '''); 2235 ''');
1900 } 2236 }
1901 2237
1902 void test_genericMethods_downwardsInferenceFold() { 2238 void test_genericMethods_downwardsInferenceFold() {
1903 // Regression from https://github.com/dart-lang/sdk/issues/25491 2239 // Regression from https://github.com/dart-lang/sdk/issues/25491
(...skipping 16 matching lines...) Expand all
1920 } 2256 }
1921 2257
1922 void test_genericMethods_handleOverrideOfNonGenericWithGeneric() { 2258 void test_genericMethods_handleOverrideOfNonGenericWithGeneric() {
1923 // Regression test for crash when adding genericity 2259 // Regression test for crash when adding genericity
1924 checkFile(''' 2260 checkFile('''
1925 class C { 2261 class C {
1926 m(x) => x; 2262 m(x) => x;
1927 dynamic g(int x) => x; 2263 dynamic g(int x) => x;
1928 } 2264 }
1929 class D extends C { 2265 class D extends C {
2266 T m<T>(T x) => x;
2267 T g<T>(T x) => x;
2268 }
2269 main() {
2270 int y = /*info:DYNAMIC_CAST*/(/*info:UNNECESSARY_CAST*/new D() as C).m(42);
2271 print(y);
2272 }
2273 ''');
2274 }
2275
2276 void test_genericMethods_handleOverrideOfNonGenericWithGeneric_comment() {
2277 // Regression test for crash when adding genericity
2278 checkFile('''
2279 class C {
2280 m(x) => x;
2281 dynamic g(int x) => x;
2282 }
2283 class D extends C {
1930 /*=T*/ m/*<T>*/(/*=T*/ x) => x; 2284 /*=T*/ m/*<T>*/(/*=T*/ x) => x;
1931 /*=T*/ g/*<T>*/(/*=T*/ x) => x; 2285 /*=T*/ g/*<T>*/(/*=T*/ x) => x;
1932 } 2286 }
1933 main() { 2287 main() {
1934 int y = /*info:DYNAMIC_CAST*/(/*info:UNNECESSARY_CAST*/new D() as C).m(42); 2288 int y = /*info:DYNAMIC_CAST*/(/*info:UNNECESSARY_CAST*/new D() as C).m(42);
1935 print(y); 2289 print(y);
1936 } 2290 }
1937 '''); 2291 ''');
1938 } 2292 }
1939 2293
1940 void test_genericMethods_inferenceError() { 2294 void test_genericMethods_inferenceError() {
1941 checkFile(r''' 2295 checkFile(r'''
1942 main() { 2296 main() {
1943 List<String> y; 2297 List<String> y;
1944 Iterable<String> x = y./*error:COULD_NOT_INFER*/map(/*error:ARGUMENT_TYPE_NOT_ ASSIGNABLE*/(String z) => 1.0); 2298 Iterable<String> x = y./*error:COULD_NOT_INFER*/map(/*error:ARGUMENT_TYPE_NOT_ ASSIGNABLE*/(String z) => 1.0);
1945 } 2299 }
1946 '''); 2300 ''');
1947 } 2301 }
1948 2302
1949 void test_genericMethods_inferGenericFunctionParameterType() { 2303 void test_genericMethods_inferGenericFunctionParameterType() {
1950 var mainUnit = checkFile(''' 2304 var mainUnit = checkFile('''
1951 class C<T> extends D<T> { 2305 class C<T> extends D<T> {
1952 f/*<U>*/(x) {} 2306 f<U>(x) {}
1953 } 2307 }
1954 class D<T> { 2308 class D<T> {
1955 F/*<U>*/ f/*<U>*/(/*=U*/ u) => null; 2309 F<U> f<U>(U u) => null;
1956 } 2310 }
1957 typedef void F<V>(V v); 2311 typedef void F<V>(V v);
1958 '''); 2312 ''');
1959 var f = mainUnit.getType('C').methods[0]; 2313 var f = mainUnit.getType('C').methods[0];
1960 expect(f.type.toString(), '<U>(U) → (U) → void'); 2314 expect(f.type.toString(), '<U>(U) → (U) → void');
1961 } 2315 }
1962 2316
1963 void test_genericMethods_inferGenericFunctionParameterType2() { 2317 void test_genericMethods_inferGenericFunctionParameterType2() {
1964 var mainUnit = checkFile(''' 2318 var mainUnit = checkFile('''
1965 class C<T> extends D<T> { 2319 class C<T> extends D<T> {
2320 f<U>(g) => null;
2321 }
2322 abstract class D<T> {
2323 void f<U>(G<U> g);
2324 }
2325 typedef List<V> G<V>();
2326 ''');
2327 var f = mainUnit.getType('C').methods[0];
2328 expect(f.type.toString(), '<U>(() → List<U>) → void');
2329 }
2330
2331 void test_genericMethods_inferGenericFunctionParameterType2_comment() {
2332 var mainUnit = checkFile('''
2333 class C<T> extends D<T> {
1966 f/*<U>*/(g) => null; 2334 f/*<U>*/(g) => null;
1967 } 2335 }
1968 abstract class D<T> { 2336 abstract class D<T> {
1969 void f/*<U>*/(G/*<U>*/ g); 2337 void f/*<U>*/(G/*<U>*/ g);
1970 } 2338 }
1971 typedef List<V> G<V>(); 2339 typedef List<V> G<V>();
1972 '''); 2340 ''');
1973 var f = mainUnit.getType('C').methods[0]; 2341 var f = mainUnit.getType('C').methods[0];
1974 expect(f.type.toString(), '<U>(() → List<U>) → void'); 2342 expect(f.type.toString(), '<U>(() → List<U>) → void');
1975 } 2343 }
1976 2344
2345 void test_genericMethods_inferGenericFunctionParameterType_comment() {
2346 var mainUnit = checkFile('''
2347 class C<T> extends D<T> {
2348 f/*<U>*/(x) {}
2349 }
2350 class D<T> {
2351 F/*<U>*/ f/*<U>*/(/*=U*/ u) => null;
2352 }
2353 typedef void F<V>(V v);
2354 ''');
2355 var f = mainUnit.getType('C').methods[0];
2356 expect(f.type.toString(), '<U>(U) → (U) → void');
2357 }
2358
1977 void test_genericMethods_inferGenericFunctionReturnType() { 2359 void test_genericMethods_inferGenericFunctionReturnType() {
1978 var mainUnit = checkFile(''' 2360 var mainUnit = checkFile('''
1979 class C<T> extends D<T> { 2361 class C<T> extends D<T> {
2362 f<U>(x) {}
2363 }
2364 class D<T> {
2365 F<U> f<U>(U u) => null;
2366 }
2367 typedef V F<V>();
2368 ''');
2369 var f = mainUnit.getType('C').methods[0];
2370 expect(f.type.toString(), '<U>(U) → () → U');
2371 }
2372
2373 void test_genericMethods_inferGenericFunctionReturnType_comment() {
2374 var mainUnit = checkFile('''
2375 class C<T> extends D<T> {
1980 f/*<U>*/(x) {} 2376 f/*<U>*/(x) {}
1981 } 2377 }
1982 class D<T> { 2378 class D<T> {
1983 F/*<U>*/ f/*<U>*/(/*=U*/ u) => null; 2379 F/*<U>*/ f/*<U>*/(/*=U*/ u) => null;
1984 } 2380 }
1985 typedef V F<V>(); 2381 typedef V F<V>();
1986 '''); 2382 ''');
1987 var f = mainUnit.getType('C').methods[0]; 2383 var f = mainUnit.getType('C').methods[0];
1988 expect(f.type.toString(), '<U>(U) → () → U'); 2384 expect(f.type.toString(), '<U>(U) → () → U');
1989 } 2385 }
1990 2386
1991 void test_genericMethods_inferGenericInstantiation() { 2387 void test_genericMethods_inferGenericInstantiation() {
1992 checkFile(''' 2388 checkFile('''
1993 import 'dart:math' as math; 2389 import 'dart:math' as math;
1994 import 'dart:math' show min; 2390 import 'dart:math' show min;
2391
2392 class C {
2393 T m<T extends num>(T x, T y) => null;
2394 }
2395
2396 main() {
2397 takeIII(math.max);
2398 takeDDD(math.max);
2399 takeNNN(math.max);
2400 takeIDN(math.max);
2401 takeDIN(math.max);
2402 takeIIN(math.max);
2403 takeDDN(math.max);
2404 takeIIO(math.max);
2405 takeDDO(math.max);
2406
2407 takeOOI(/*error:ARGUMENT_TYPE_NOT_ASSIGNABLE*/math.max);
2408 takeIDI(/*error:ARGUMENT_TYPE_NOT_ASSIGNABLE*/math.max);
2409 takeDID(/*error:ARGUMENT_TYPE_NOT_ASSIGNABLE*/math.max);
2410 takeOON(/*error:ARGUMENT_TYPE_NOT_ASSIGNABLE*/math.max);
2411 takeOOO(/*error:ARGUMENT_TYPE_NOT_ASSIGNABLE*/math.max);
2412
2413 // Also test SimpleIdentifier
2414 takeIII(min);
2415 takeDDD(min);
2416 takeNNN(min);
2417 takeIDN(min);
2418 takeDIN(min);
2419 takeIIN(min);
2420 takeDDN(min);
2421 takeIIO(min);
2422 takeDDO(min);
2423
2424 takeOOI(/*error:ARGUMENT_TYPE_NOT_ASSIGNABLE*/min);
2425 takeIDI(/*error:ARGUMENT_TYPE_NOT_ASSIGNABLE*/min);
2426 takeDID(/*error:ARGUMENT_TYPE_NOT_ASSIGNABLE*/min);
2427 takeOON(/*error:ARGUMENT_TYPE_NOT_ASSIGNABLE*/min);
2428 takeOOO(/*error:ARGUMENT_TYPE_NOT_ASSIGNABLE*/min);
2429
2430 // Also PropertyAccess
2431 takeIII(new C().m);
2432 takeDDD(new C().m);
2433 takeNNN(new C().m);
2434 takeIDN(new C().m);
2435 takeDIN(new C().m);
2436 takeIIN(new C().m);
2437 takeDDN(new C().m);
2438 takeIIO(new C().m);
2439 takeDDO(new C().m);
2440
2441 // Note: this is a warning because a downcast of a method tear-off could work
2442 // (derived method can be a subtype):
2443 //
2444 // class D extends C {
2445 // S m<S extends num>(Object x, Object y);
2446 // }
2447 //
2448 // That's legal because we're loosening parameter types.
2449 //
2450 takeOON(/*error:ARGUMENT_TYPE_NOT_ASSIGNABLE*/new C().m);
2451 takeOOO(/*error:ARGUMENT_TYPE_NOT_ASSIGNABLE*/new C().m);
2452
2453 // Note: this is a warning because a downcast of a method tear-off could work
2454 // in "normal" Dart, due to bivariance.
2455 takeOOI(/*error:ARGUMENT_TYPE_NOT_ASSIGNABLE*/new C().m);
2456 takeIDI(/*error:ARGUMENT_TYPE_NOT_ASSIGNABLE*/new C().m);
2457 takeDID(/*error:ARGUMENT_TYPE_NOT_ASSIGNABLE*/new C().m);
2458 }
2459
2460 void takeIII(int fn(int a, int b)) {}
2461 void takeDDD(double fn(double a, double b)) {}
2462 void takeIDI(int fn(double a, int b)) {}
2463 void takeDID(double fn(int a, double b)) {}
2464 void takeIDN(num fn(double a, int b)) {}
2465 void takeDIN(num fn(int a, double b)) {}
2466 void takeIIN(num fn(int a, int b)) {}
2467 void takeDDN(num fn(double a, double b)) {}
2468 void takeNNN(num fn(num a, num b)) {}
2469 void takeOON(num fn(Object a, Object b)) {}
2470 void takeOOO(num fn(Object a, Object b)) {}
2471 void takeOOI(int fn(Object a, Object b)) {}
2472 void takeIIO(Object fn(int a, int b)) {}
2473 void takeDDO(Object fn(double a, double b)) {}
2474 ''');
2475 }
2476
2477 void test_genericMethods_inferGenericInstantiation_comment() {
2478 checkFile('''
2479 import 'dart:math' as math;
2480 import 'dart:math' show min;
1995 2481
1996 class C { 2482 class C {
1997 /*=T*/ m/*<T extends num>*/(/*=T*/ x, /*=T*/ y) => null; 2483 /*=T*/ m/*<T extends num>*/(/*=T*/ x, /*=T*/ y) => null;
1998 } 2484 }
1999 2485
2000 main() { 2486 main() {
2001 takeIII(math.max); 2487 takeIII(math.max);
2002 takeDDD(math.max); 2488 takeDDD(math.max);
2003 takeNNN(math.max); 2489 takeNNN(math.max);
2004 takeIDN(math.max); 2490 takeIDN(math.max);
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
2075 void takeOOI(int fn(Object a, Object b)) {} 2561 void takeOOI(int fn(Object a, Object b)) {}
2076 void takeIIO(Object fn(int a, int b)) {} 2562 void takeIIO(Object fn(int a, int b)) {}
2077 void takeDDO(Object fn(double a, double b)) {} 2563 void takeDDO(Object fn(double a, double b)) {}
2078 '''); 2564 ''');
2079 } 2565 }
2080 2566
2081 void test_genericMethods_inferGenericMethodType() { 2567 void test_genericMethods_inferGenericMethodType() {
2082 // Regression test for https://github.com/dart-lang/sdk/issues/25668 2568 // Regression test for https://github.com/dart-lang/sdk/issues/25668
2083 checkFile(''' 2569 checkFile('''
2084 class C { 2570 class C {
2571 T m<T>(T x) => x;
2572 }
2573 class D extends C {
2574 m<S>(x) => x;
2575 }
2576 main() {
2577 int y = new D().m<int>(42);
2578 print(y);
2579 }
2580 ''');
2581 }
2582
2583 void test_genericMethods_inferGenericMethodType_comment() {
2584 // Regression test for https://github.com/dart-lang/sdk/issues/25668
2585 checkFile('''
2586 class C {
2085 /*=T*/ m/*<T>*/(/*=T*/ x) => x; 2587 /*=T*/ m/*<T>*/(/*=T*/ x) => x;
2086 } 2588 }
2087 class D extends C { 2589 class D extends C {
2088 m/*<S>*/(x) => x; 2590 m/*<S>*/(x) => x;
2089 } 2591 }
2090 main() { 2592 main() {
2091 int y = new D().m/*<int>*/(42); 2593 int y = new D().m/*<int>*/(42);
2092 print(y); 2594 print(y);
2093 } 2595 }
2094 '''); 2596 ''');
(...skipping 26 matching lines...) Expand all
2121 => list.fold('', /*info:INFERRED_TYPE_CLOSURE*/(x, y) => x + y.toString())); 2623 => list.fold('', /*info:INFERRED_TYPE_CLOSURE*/(x, y) => x + y.toString()));
2122 } 2624 }
2123 '''); 2625 ''');
2124 } 2626 }
2125 2627
2126 void test_genericMethods_usesGreatestLowerBound() { 2628 void test_genericMethods_usesGreatestLowerBound() {
2127 var mainUnit = checkFile(r''' 2629 var mainUnit = checkFile(r'''
2128 typedef Iterable<num> F(int x); 2630 typedef Iterable<num> F(int x);
2129 typedef List<int> G(double x); 2631 typedef List<int> G(double x);
2130 2632
2633 T generic<T>(a(T _), b(T _)) => null;
2634
2635 var v = generic((F f) => null, (G g) => null);
2636 ''');
2637 var v = mainUnit.topLevelVariables[0];
2638 expect(v.type.toString(), '(num) → List<int>');
2639 }
2640
2641 void test_genericMethods_usesGreatestLowerBound_comment() {
2642 var mainUnit = checkFile(r'''
2643 typedef Iterable<num> F(int x);
2644 typedef List<int> G(double x);
2645
2131 /*=T*/ generic/*<T>*/(a(/*=T*/ _), b(/*=T*/ _)) => null; 2646 /*=T*/ generic/*<T>*/(a(/*=T*/ _), b(/*=T*/ _)) => null;
2132 2647
2133 var v = generic((F f) => null, (G g) => null); 2648 var v = generic((F f) => null, (G g) => null);
2134 '''); 2649 ''');
2135 var v = mainUnit.topLevelVariables[0]; 2650 var v = mainUnit.topLevelVariables[0];
2136 expect(v.type.toString(), '(num) → List<int>'); 2651 expect(v.type.toString(), '(num) → List<int>');
2137 } 2652 }
2138 2653
2139 void test_infer_assignToIndex() { 2654 void test_infer_assignToIndex() {
2140 checkFile(r''' 2655 checkFile(r'''
(...skipping 564 matching lines...) Expand 10 before | Expand all | Expand 10 after
2705 test1() { 3220 test1() {
2706 A.x = /*error:INVALID_ASSIGNMENT*/"hi"; 3221 A.x = /*error:INVALID_ASSIGNMENT*/"hi";
2707 B.y = /*error:INVALID_ASSIGNMENT*/"hi"; 3222 B.y = /*error:INVALID_ASSIGNMENT*/"hi";
2708 } 3223 }
2709 '''); 3224 ''');
2710 } 3225 }
2711 3226
2712 void test_inferGenericMethodType_named() { 3227 void test_inferGenericMethodType_named() {
2713 var unit = checkFile(''' 3228 var unit = checkFile('''
2714 class C { 3229 class C {
3230 T m<T>(int a, {String b, T c}) => null;
3231 }
3232 var y = new C().m(1, b: 'bbb', c: 2.0);
3233 ''');
3234 expect(unit.topLevelVariables[0].type.toString(), 'double');
3235 }
3236
3237 void test_inferGenericMethodType_named_comment() {
3238 var unit = checkFile('''
3239 class C {
2715 /*=T*/ m/*<T>*/(int a, {String b, /*=T*/ c}) => null; 3240 /*=T*/ m/*<T>*/(int a, {String b, /*=T*/ c}) => null;
2716 } 3241 }
2717 var y = new C().m(1, b: 'bbb', c: 2.0); 3242 var y = new C().m(1, b: 'bbb', c: 2.0);
2718 '''); 3243 ''');
2719 expect(unit.topLevelVariables[0].type.toString(), 'double'); 3244 expect(unit.topLevelVariables[0].type.toString(), 'double');
2720 } 3245 }
2721 3246
2722 void test_inferGenericMethodType_positional() { 3247 void test_inferGenericMethodType_positional() {
2723 var unit = checkFile(''' 3248 var unit = checkFile('''
2724 class C { 3249 class C {
2725 /*=T*/ m/*<T>*/(int a, [/*=T*/ b]) => null; 3250 T m<T>(int a, [T b]) => null;
2726 } 3251 }
2727 var y = new C().m(1, 2.0); 3252 var y = new C().m(1, 2.0);
2728 '''); 3253 ''');
2729 expect(unit.topLevelVariables[0].type.toString(), 'double'); 3254 expect(unit.topLevelVariables[0].type.toString(), 'double');
2730 } 3255 }
2731 3256
2732 void test_inferGenericMethodType_positional2() { 3257 void test_inferGenericMethodType_positional2() {
2733 var unit = checkFile(''' 3258 var unit = checkFile('''
2734 class C { 3259 class C {
3260 T m<T>(int a, [String b, T c]) => null;
3261 }
3262 var y = new C().m(1, 'bbb', 2.0);
3263 ''');
3264 expect(unit.topLevelVariables[0].type.toString(), 'double');
3265 }
3266
3267 void test_inferGenericMethodType_positional2_comment() {
3268 var unit = checkFile('''
3269 class C {
2735 /*=T*/ m/*<T>*/(int a, [String b, /*=T*/ c]) => null; 3270 /*=T*/ m/*<T>*/(int a, [String b, /*=T*/ c]) => null;
2736 } 3271 }
2737 var y = new C().m(1, 'bbb', 2.0); 3272 var y = new C().m(1, 'bbb', 2.0);
2738 '''); 3273 ''');
2739 expect(unit.topLevelVariables[0].type.toString(), 'double'); 3274 expect(unit.topLevelVariables[0].type.toString(), 'double');
2740 } 3275 }
2741 3276
3277 void test_inferGenericMethodType_positional_comment() {
3278 var unit = checkFile('''
3279 class C {
3280 /*=T*/ m/*<T>*/(int a, [/*=T*/ b]) => null;
3281 }
3282 var y = new C().m(1, 2.0);
3283 ''');
3284 expect(unit.topLevelVariables[0].type.toString(), 'double');
3285 }
3286
2742 void test_inferGenericMethodType_required() { 3287 void test_inferGenericMethodType_required() {
2743 var unit = checkFile(''' 3288 var unit = checkFile('''
2744 class C { 3289 class C {
3290 T m<T>(T x) => x;
3291 }
3292 var y = new C().m(42);
3293 ''');
3294 expect(unit.topLevelVariables[0].type.toString(), 'int');
3295 }
3296
3297 void test_inferGenericMethodType_required_comment() {
3298 var unit = checkFile('''
3299 class C {
2745 /*=T*/ m/*<T>*/(/*=T*/ x) => x; 3300 /*=T*/ m/*<T>*/(/*=T*/ x) => x;
2746 } 3301 }
2747 var y = new C().m(42); 3302 var y = new C().m(42);
2748 '''); 3303 ''');
2749 expect(unit.topLevelVariables[0].type.toString(), 'int'); 3304 expect(unit.topLevelVariables[0].type.toString(), 'int');
2750 } 3305 }
2751 3306
2752 void test_inferIfComplexExpressionsReadPossibleInferredField() { 3307 void test_inferIfComplexExpressionsReadPossibleInferredField() {
2753 // but flags can enable this behavior. 3308 // but flags can enable this behavior.
2754 addFile( 3309 addFile(
(...skipping 1196 matching lines...) Expand 10 before | Expand all | Expand 10 after
3951 var unit = checkFile(r''' 4506 var unit = checkFile(r'''
3952 var x = { null: null }; 4507 var x = { null: null };
3953 '''); 4508 ''');
3954 var x = unit.topLevelVariables[0]; 4509 var x = unit.topLevelVariables[0];
3955 expect(x.type.toString(), 'Map<dynamic, dynamic>'); 4510 expect(x.type.toString(), 'Map<dynamic, dynamic>');
3956 } 4511 }
3957 4512
3958 void test_methodCall_withTypeArguments_instanceMethod() { 4513 void test_methodCall_withTypeArguments_instanceMethod() {
3959 var mainUnit = checkFile(''' 4514 var mainUnit = checkFile('''
3960 class C { 4515 class C {
4516 D<T> f<T>() => null;
4517 }
4518 class D<T> {}
4519 var f = new C().f<int>();
4520 ''');
4521 var v = mainUnit.topLevelVariables[0];
4522 expect(v.type.toString(), 'D<int>');
4523 }
4524
4525 void test_methodCall_withTypeArguments_instanceMethod_comment() {
4526 var mainUnit = checkFile('''
4527 class C {
3961 D/*<T>*/ f/*<T>*/() => null; 4528 D/*<T>*/ f/*<T>*/() => null;
3962 } 4529 }
3963 class D<T> {} 4530 class D<T> {}
3964 var f = new C().f/*<int>*/(); 4531 var f = new C().f/*<int>*/();
3965 '''); 4532 ''');
3966 var v = mainUnit.topLevelVariables[0]; 4533 var v = mainUnit.topLevelVariables[0];
3967 expect(v.type.toString(), 'D<int>'); 4534 expect(v.type.toString(), 'D<int>');
3968 } 4535 }
3969 4536
3970 void test_methodCall_withTypeArguments_instanceMethod_identifierSequence() { 4537 void test_methodCall_withTypeArguments_instanceMethod_identifierSequence() {
3971 var mainUnit = checkFile(''' 4538 var mainUnit = checkFile('''
3972 class C { 4539 class C {
4540 D<T> f<T>() => null;
4541 }
4542 class D<T> {}
4543 C c;
4544 var f = c.f<int>();
4545 ''');
4546 var v = mainUnit.topLevelVariables[1];
4547 expect(v.name, 'f');
4548 expect(v.type.toString(), 'D<int>');
4549 }
4550
4551 void
4552 test_methodCall_withTypeArguments_instanceMethod_identifierSequence_commen t() {
4553 var mainUnit = checkFile('''
4554 class C {
3973 D/*<T>*/ f/*<T>*/() => null; 4555 D/*<T>*/ f/*<T>*/() => null;
3974 } 4556 }
3975 class D<T> {} 4557 class D<T> {}
3976 C c; 4558 C c;
3977 var f = c.f/*<int>*/(); 4559 var f = c.f/*<int>*/();
3978 '''); 4560 ''');
3979 var v = mainUnit.topLevelVariables[1]; 4561 var v = mainUnit.topLevelVariables[1];
3980 expect(v.name, 'f'); 4562 expect(v.name, 'f');
3981 expect(v.type.toString(), 'D<int>'); 4563 expect(v.type.toString(), 'D<int>');
3982 } 4564 }
3983 4565
3984 void test_methodCall_withTypeArguments_staticMethod() { 4566 void test_methodCall_withTypeArguments_staticMethod() {
3985 var mainUnit = checkFile(''' 4567 var mainUnit = checkFile('''
3986 class C { 4568 class C {
4569 static D<T> f<T>() => null;
4570 }
4571 class D<T> {}
4572 var f = C.f<int>();
4573 ''');
4574 var v = mainUnit.topLevelVariables[0];
4575 expect(v.type.toString(), 'D<int>');
4576 }
4577
4578 void test_methodCall_withTypeArguments_staticMethod_comment() {
4579 var mainUnit = checkFile('''
4580 class C {
3987 static D/*<T>*/ f/*<T>*/() => null; 4581 static D/*<T>*/ f/*<T>*/() => null;
3988 } 4582 }
3989 class D<T> {} 4583 class D<T> {}
3990 var f = C.f/*<int>*/(); 4584 var f = C.f/*<int>*/();
3991 '''); 4585 ''');
3992 var v = mainUnit.topLevelVariables[0]; 4586 var v = mainUnit.topLevelVariables[0];
3993 expect(v.type.toString(), 'D<int>'); 4587 expect(v.type.toString(), 'D<int>');
3994 } 4588 }
3995 4589
3996 void test_methodCall_withTypeArguments_topLevelFunction() { 4590 void test_methodCall_withTypeArguments_topLevelFunction() {
3997 var mainUnit = checkFile(''' 4591 var mainUnit = checkFile('''
4592 D<T> f<T>() => null;
4593 class D<T> {}
4594 var g = f<int>();
4595 ''');
4596 var v = mainUnit.topLevelVariables[0];
4597 expect(v.type.toString(), 'D<int>');
4598 }
4599
4600 void test_methodCall_withTypeArguments_topLevelFunction_comment() {
4601 var mainUnit = checkFile('''
3998 D/*<T>*/ f/*<T>*/() => null; 4602 D/*<T>*/ f/*<T>*/() => null;
3999 class D<T> {} 4603 class D<T> {}
4000 var g = f/*<int>*/(); 4604 var g = f/*<int>*/();
4001 '''); 4605 ''');
4002 var v = mainUnit.topLevelVariables[0]; 4606 var v = mainUnit.topLevelVariables[0];
4003 expect(v.type.toString(), 'D<int>'); 4607 expect(v.type.toString(), 'D<int>');
4004 } 4608 }
4005 4609
4006 void test_noErrorWhenDeclaredTypeIsNumAndAssignedNull() { 4610 void test_noErrorWhenDeclaredTypeIsNumAndAssignedNull() {
4007 checkFile(''' 4611 checkFile('''
(...skipping 366 matching lines...) Expand 10 before | Expand all | Expand 10 after
4374 } 4978 }
4375 var v = new C(/*info:INFERRED_TYPE_CLOSURE*/() { return 1; }); 4979 var v = new C(/*info:INFERRED_TYPE_CLOSURE*/() { return 1; });
4376 '''); 4980 ''');
4377 var v = mainUnit.topLevelVariables[0]; 4981 var v = mainUnit.topLevelVariables[0];
4378 expect(v.name, 'v'); 4982 expect(v.name, 'v');
4379 expect(v.type.toString(), 'C'); 4983 expect(v.type.toString(), 'C');
4380 } 4984 }
4381 4985
4382 void test_unsafeBlockClosureInference_functionCall_explicitDynamicParam() { 4986 void test_unsafeBlockClosureInference_functionCall_explicitDynamicParam() {
4383 var mainUnit = checkFile(''' 4987 var mainUnit = checkFile('''
4988 List<T> f<T>(T g()) => <T>[g()];
4989 var v = f<dynamic>(/*info:INFERRED_TYPE_CLOSURE*/() { return 1; });
4990 ''');
4991 var v = mainUnit.topLevelVariables[0];
4992 expect(v.name, 'v');
4993 expect(v.type.toString(), 'List<dynamic>');
4994 }
4995
4996 void
4997 test_unsafeBlockClosureInference_functionCall_explicitDynamicParam_comment () {
4998 var mainUnit = checkFile('''
4384 dynamic /*=List<T>*/ f/*<T>*/(dynamic/*=T*/ g()) => <T>[g()]; 4999 dynamic /*=List<T>*/ f/*<T>*/(dynamic/*=T*/ g()) => <T>[g()];
4385 var v = f/*<dynamic>*/(/*info:INFERRED_TYPE_CLOSURE*/() { return 1; }); 5000 var v = f/*<dynamic>*/(/*info:INFERRED_TYPE_CLOSURE*/() { return 1; });
4386 '''); 5001 ''');
4387 var v = mainUnit.topLevelVariables[0]; 5002 var v = mainUnit.topLevelVariables[0];
4388 expect(v.name, 'v'); 5003 expect(v.name, 'v');
4389 expect(v.type.toString(), 'List<dynamic>'); 5004 expect(v.type.toString(), 'List<dynamic>');
4390 } 5005 }
4391 5006
4392 @failingTest 5007 @failingTest
4393 void 5008 void
4394 test_unsafeBlockClosureInference_functionCall_explicitDynamicParam_viaExpr 1() { 5009 test_unsafeBlockClosureInference_functionCall_explicitDynamicParam_viaExpr 1() {
4395 // Note: (f/*<dynamic>*/) is nort properly resulting in an instantiated 5010 // Note: (f/*<dynamic>*/) is nort properly resulting in an instantiated
4396 // function type due to dartbug.com/25824. 5011 // function type due to dartbug.com/25824.
4397 var mainUnit = checkFile(''' 5012 var mainUnit = checkFile('''
5013 List<T> f<T>(T g()) => <T>[g()];
5014 var v = (f<dynamic>)(/*info:INFERRED_TYPE_CLOSURE*/() { return 1; });
5015 ''');
5016 var v = mainUnit.topLevelVariables[0];
5017 expect(v.name, 'v');
5018 expect(v.type.toString(), 'List<dynamic>');
5019 }
5020
5021 @failingTest
5022 void
5023 test_unsafeBlockClosureInference_functionCall_explicitDynamicParam_viaExpr 1_comment() {
5024 // Note: (f/*<dynamic>*/) is nort properly resulting in an instantiated
5025 // function type due to dartbug.com/25824.
5026 var mainUnit = checkFile('''
4398 dynamic /*=List<T>*/ f/*<T>*/(dynamic/*=T*/ g()) => <T>[g()]; 5027 dynamic /*=List<T>*/ f/*<T>*/(dynamic/*=T*/ g()) => <T>[g()];
4399 var v = (f/*<dynamic>*/)(/*info:INFERRED_TYPE_CLOSURE*/() { return 1; }); 5028 var v = (f/*<dynamic>*/)(/*info:INFERRED_TYPE_CLOSURE*/() { return 1; });
4400 '''); 5029 ''');
4401 var v = mainUnit.topLevelVariables[0]; 5030 var v = mainUnit.topLevelVariables[0];
4402 expect(v.name, 'v'); 5031 expect(v.name, 'v');
4403 expect(v.type.toString(), 'List<dynamic>'); 5032 expect(v.type.toString(), 'List<dynamic>');
4404 } 5033 }
4405 5034
4406 void 5035 void
4407 test_unsafeBlockClosureInference_functionCall_explicitDynamicParam_viaExpr 2() { 5036 test_unsafeBlockClosureInference_functionCall_explicitDynamicParam_viaExpr 2() {
4408 var mainUnit = checkFile(''' 5037 var mainUnit = checkFile('''
5038 List<T> f<T>(T g()) => <T>[g()];
5039 var v = (f)<dynamic>(/*info:INFERRED_TYPE_CLOSURE*/() { return 1; });
5040 ''');
5041 var v = mainUnit.topLevelVariables[0];
5042 expect(v.name, 'v');
5043 expect(v.type.toString(), 'List<dynamic>');
5044 }
5045
5046 void
5047 test_unsafeBlockClosureInference_functionCall_explicitDynamicParam_viaExpr 2_comment() {
5048 var mainUnit = checkFile('''
4409 dynamic /*=List<T>*/ f/*<T>*/(dynamic/*=T*/ g()) => <T>[g()]; 5049 dynamic /*=List<T>*/ f/*<T>*/(dynamic/*=T*/ g()) => <T>[g()];
4410 var v = (f)/*<dynamic>*/(/*info:INFERRED_TYPE_CLOSURE*/() { return 1; }); 5050 var v = (f)/*<dynamic>*/(/*info:INFERRED_TYPE_CLOSURE*/() { return 1; });
4411 '''); 5051 ''');
4412 var v = mainUnit.topLevelVariables[0]; 5052 var v = mainUnit.topLevelVariables[0];
4413 expect(v.name, 'v'); 5053 expect(v.name, 'v');
4414 expect(v.type.toString(), 'List<dynamic>'); 5054 expect(v.type.toString(), 'List<dynamic>');
4415 } 5055 }
4416 5056
4417 void test_unsafeBlockClosureInference_functionCall_explicitTypeParam() { 5057 void test_unsafeBlockClosureInference_functionCall_explicitTypeParam() {
4418 var mainUnit = checkFile(''' 5058 var mainUnit = checkFile('''
5059 List<T> f<T>(T g()) => <T>[g()];
5060 var v = f<int>(/*info:INFERRED_TYPE_CLOSURE*/() { return 1; });
5061 ''');
5062 var v = mainUnit.topLevelVariables[0];
5063 expect(v.name, 'v');
5064 expect(v.type.toString(), 'List<int>');
5065 }
5066
5067 void
5068 test_unsafeBlockClosureInference_functionCall_explicitTypeParam_comment() {
5069 var mainUnit = checkFile('''
4419 dynamic /*=List<T>*/ f/*<T>*/(dynamic/*=T*/ g()) => <T>[g()]; 5070 dynamic /*=List<T>*/ f/*<T>*/(dynamic/*=T*/ g()) => <T>[g()];
4420 var v = f/*<int>*/(/*info:INFERRED_TYPE_CLOSURE*/() { return 1; }); 5071 var v = f/*<int>*/(/*info:INFERRED_TYPE_CLOSURE*/() { return 1; });
4421 '''); 5072 ''');
4422 var v = mainUnit.topLevelVariables[0]; 5073 var v = mainUnit.topLevelVariables[0];
4423 expect(v.name, 'v'); 5074 expect(v.name, 'v');
4424 expect(v.type.toString(), 'List<int>'); 5075 expect(v.type.toString(), 'List<int>');
4425 } 5076 }
4426 5077
4427 @failingTest 5078 @failingTest
4428 void 5079 void
4429 test_unsafeBlockClosureInference_functionCall_explicitTypeParam_viaExpr1() { 5080 test_unsafeBlockClosureInference_functionCall_explicitTypeParam_viaExpr1() {
4430 // TODO(paulberry): for some reason (f/*<int>) is nort properly resulting 5081 // TODO(paulberry): for some reason (f/*<int>) is nort properly resulting
4431 // in an instantiated function type. 5082 // in an instantiated function type.
4432 var mainUnit = checkFile(''' 5083 var mainUnit = checkFile('''
5084 List<T> f<T>(T g()) => <T>[g()];
5085 var v = (f/int>)(/*info:INFERRED_TYPE_CLOSURE*/() { return 1; });
5086 ''');
5087 var v = mainUnit.topLevelVariables[0];
5088 expect(v.name, 'v');
5089 expect(v.type.toString(), 'List<int>');
5090 }
5091
5092 @failingTest
5093 void
5094 test_unsafeBlockClosureInference_functionCall_explicitTypeParam_viaExpr1_c omment() {
5095 // TODO(paulberry): for some reason (f/*<int>) is nort properly resulting
5096 // in an instantiated function type.
5097 var mainUnit = checkFile('''
4433 dynamic /*=List<T>*/ f/*<T>*/(dynamic/*=T*/ g()) => <T>[g()]; 5098 dynamic /*=List<T>*/ f/*<T>*/(dynamic/*=T*/ g()) => <T>[g()];
4434 var v = (f/*<int>*/)(/*info:INFERRED_TYPE_CLOSURE*/() { return 1; }); 5099 var v = (f/*<int>*/)(/*info:INFERRED_TYPE_CLOSURE*/() { return 1; });
4435 '''); 5100 ''');
4436 var v = mainUnit.topLevelVariables[0]; 5101 var v = mainUnit.topLevelVariables[0];
4437 expect(v.name, 'v'); 5102 expect(v.name, 'v');
4438 expect(v.type.toString(), 'List<int>'); 5103 expect(v.type.toString(), 'List<int>');
4439 } 5104 }
4440 5105
4441 void 5106 void
4442 test_unsafeBlockClosureInference_functionCall_explicitTypeParam_viaExpr2() { 5107 test_unsafeBlockClosureInference_functionCall_explicitTypeParam_viaExpr2() {
4443 var mainUnit = checkFile(''' 5108 var mainUnit = checkFile('''
5109 List<T> f<T>(T g()) => <T>[g()];
5110 var v = (f)<int>(/*info:INFERRED_TYPE_CLOSURE*/() { return 1; });
5111 ''');
5112 var v = mainUnit.topLevelVariables[0];
5113 expect(v.name, 'v');
5114 expect(v.type.toString(), 'List<int>');
5115 }
5116
5117 void
5118 test_unsafeBlockClosureInference_functionCall_explicitTypeParam_viaExpr2_c omment() {
5119 var mainUnit = checkFile('''
4444 dynamic /*=List<T>*/ f/*<T>*/(dynamic/*=T*/ g()) => <T>[g()]; 5120 dynamic /*=List<T>*/ f/*<T>*/(dynamic/*=T*/ g()) => <T>[g()];
4445 var v = (f)/*<int>*/(/*info:INFERRED_TYPE_CLOSURE*/() { return 1; }); 5121 var v = (f)/*<int>*/(/*info:INFERRED_TYPE_CLOSURE*/() { return 1; });
4446 '''); 5122 ''');
4447 var v = mainUnit.topLevelVariables[0]; 5123 var v = mainUnit.topLevelVariables[0];
4448 expect(v.name, 'v'); 5124 expect(v.name, 'v');
4449 expect(v.type.toString(), 'List<int>'); 5125 expect(v.type.toString(), 'List<int>');
4450 } 5126 }
4451 5127
4452 void test_unsafeBlockClosureInference_functionCall_implicitTypeParam() { 5128 void test_unsafeBlockClosureInference_functionCall_implicitTypeParam() {
4453 var mainUnit = checkFile(''' 5129 var mainUnit = checkFile('''
5130 List<T> f<T>(T g()) => <T>[g()];
5131 var v = f(
5132 /*info:INFERRED_TYPE_CLOSURE,warning:UNSAFE_BLOCK_CLOSURE_INFERENCE*/() {
5133 return 1;
5134 });
5135 ''');
5136 var v = mainUnit.topLevelVariables[0];
5137 expect(v.name, 'v');
5138 expect(v.type.toString(), 'List<int>');
5139 }
5140
5141 void
5142 test_unsafeBlockClosureInference_functionCall_implicitTypeParam_comment() {
5143 var mainUnit = checkFile('''
4454 dynamic /*=List<T>*/ f/*<T>*/(dynamic/*=T*/ g()) => <T>[g()]; 5144 dynamic /*=List<T>*/ f/*<T>*/(dynamic/*=T*/ g()) => <T>[g()];
4455 var v = f( 5145 var v = f(
4456 /*info:INFERRED_TYPE_CLOSURE,warning:UNSAFE_BLOCK_CLOSURE_INFERENCE*/() { 5146 /*info:INFERRED_TYPE_CLOSURE,warning:UNSAFE_BLOCK_CLOSURE_INFERENCE*/() {
4457 return 1; 5147 return 1;
4458 }); 5148 });
4459 '''); 5149 ''');
4460 var v = mainUnit.topLevelVariables[0]; 5150 var v = mainUnit.topLevelVariables[0];
4461 expect(v.name, 'v'); 5151 expect(v.name, 'v');
4462 expect(v.type.toString(), 'List<int>'); 5152 expect(v.type.toString(), 'List<int>');
4463 } 5153 }
4464 5154
4465 void 5155 void
4466 test_unsafeBlockClosureInference_functionCall_implicitTypeParam_viaExpr() { 5156 test_unsafeBlockClosureInference_functionCall_implicitTypeParam_viaExpr() {
4467 var mainUnit = checkFile(''' 5157 var mainUnit = checkFile('''
5158 List<T> f<T>(T g()) => <T>[g()];
5159 var v = (f)(
5160 /*info:INFERRED_TYPE_CLOSURE,warning:UNSAFE_BLOCK_CLOSURE_INFERENCE*/() {
5161 return 1;
5162 });
5163 ''');
5164 var v = mainUnit.topLevelVariables[0];
5165 expect(v.name, 'v');
5166 expect(v.type.toString(), 'List<int>');
5167 }
5168
5169 void
5170 test_unsafeBlockClosureInference_functionCall_implicitTypeParam_viaExpr_co mment() {
5171 var mainUnit = checkFile('''
4468 dynamic /*=List<T>*/ f/*<T>*/(dynamic/*=T*/ g()) => <T>[g()]; 5172 dynamic /*=List<T>*/ f/*<T>*/(dynamic/*=T*/ g()) => <T>[g()];
4469 var v = (f)( 5173 var v = (f)(
4470 /*info:INFERRED_TYPE_CLOSURE,warning:UNSAFE_BLOCK_CLOSURE_INFERENCE*/() { 5174 /*info:INFERRED_TYPE_CLOSURE,warning:UNSAFE_BLOCK_CLOSURE_INFERENCE*/() {
4471 return 1; 5175 return 1;
4472 }); 5176 });
4473 '''); 5177 ''');
4474 var v = mainUnit.topLevelVariables[0]; 5178 var v = mainUnit.topLevelVariables[0];
4475 expect(v.name, 'v'); 5179 expect(v.name, 'v');
4476 expect(v.type.toString(), 'List<int>'); 5180 expect(v.type.toString(), 'List<int>');
4477 } 5181 }
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
4554 }}; 5258 }};
4555 '''); 5259 ''');
4556 var v = mainUnit.topLevelVariables[0]; 5260 var v = mainUnit.topLevelVariables[0];
4557 expect(v.name, 'v'); 5261 expect(v.name, 'v');
4558 expect(v.type.toString(), 'Map<int, () → int>'); 5262 expect(v.type.toString(), 'Map<int, () → int>');
4559 } 5263 }
4560 5264
4561 void test_unsafeBlockClosureInference_methodCall_explicitDynamicParam() { 5265 void test_unsafeBlockClosureInference_methodCall_explicitDynamicParam() {
4562 var mainUnit = checkFile(''' 5266 var mainUnit = checkFile('''
4563 class C { 5267 class C {
5268 List<T> f<T>(T g()) => <T>[g()];
5269 }
5270 var v = new C().f<dynamic>(/*info:INFERRED_TYPE_CLOSURE*/() { return 1; });
5271 ''');
5272 var v = mainUnit.topLevelVariables[0];
5273 expect(v.name, 'v');
5274 expect(v.type.toString(), 'List<dynamic>');
5275 }
5276
5277 void
5278 test_unsafeBlockClosureInference_methodCall_explicitDynamicParam_comment() {
5279 var mainUnit = checkFile('''
5280 class C {
4564 dynamic /*=List<T>*/ f/*<T>*/(dynamic/*=T*/ g()) => <T>[g()]; 5281 dynamic /*=List<T>*/ f/*<T>*/(dynamic/*=T*/ g()) => <T>[g()];
4565 } 5282 }
4566 var v = new C().f/*<dynamic>*/(/*info:INFERRED_TYPE_CLOSURE*/() { return 1; }); 5283 var v = new C().f/*<dynamic>*/(/*info:INFERRED_TYPE_CLOSURE*/() { return 1; });
4567 '''); 5284 ''');
4568 var v = mainUnit.topLevelVariables[0]; 5285 var v = mainUnit.topLevelVariables[0];
4569 expect(v.name, 'v'); 5286 expect(v.name, 'v');
4570 expect(v.type.toString(), 'List<dynamic>'); 5287 expect(v.type.toString(), 'List<dynamic>');
4571 } 5288 }
4572 5289
4573 void test_unsafeBlockClosureInference_methodCall_explicitTypeParam() { 5290 void test_unsafeBlockClosureInference_methodCall_explicitTypeParam() {
4574 var mainUnit = checkFile(''' 5291 var mainUnit = checkFile('''
4575 class C { 5292 class C {
5293 List<T> f<T>(T g()) => <T>[g()];
5294 }
5295 var v = new C().f<int>(/*info:INFERRED_TYPE_CLOSURE*/() { return 1; });
5296 ''');
5297 var v = mainUnit.topLevelVariables[0];
5298 expect(v.name, 'v');
5299 expect(v.type.toString(), 'List<int>');
5300 }
5301
5302 void test_unsafeBlockClosureInference_methodCall_explicitTypeParam_comment() {
5303 var mainUnit = checkFile('''
5304 class C {
4576 dynamic /*=List<T>*/ f/*<T>*/(dynamic/*=T*/ g()) => <T>[g()]; 5305 dynamic /*=List<T>*/ f/*<T>*/(dynamic/*=T*/ g()) => <T>[g()];
4577 } 5306 }
4578 var v = new C().f/*<int>*/(/*info:INFERRED_TYPE_CLOSURE*/() { return 1; }); 5307 var v = new C().f/*<int>*/(/*info:INFERRED_TYPE_CLOSURE*/() { return 1; });
4579 '''); 5308 ''');
4580 var v = mainUnit.topLevelVariables[0]; 5309 var v = mainUnit.topLevelVariables[0];
4581 expect(v.name, 'v'); 5310 expect(v.name, 'v');
4582 expect(v.type.toString(), 'List<int>'); 5311 expect(v.type.toString(), 'List<int>');
4583 } 5312 }
4584 5313
4585 void test_unsafeBlockClosureInference_methodCall_implicitTypeParam() { 5314 void test_unsafeBlockClosureInference_methodCall_implicitTypeParam() {
4586 var mainUnit = checkFile(''' 5315 var mainUnit = checkFile('''
4587 class C { 5316 class C {
5317 List<T> f<T>(T g()) => <T>[g()];
5318 }
5319 var v = new C().f(
5320 /*info:INFERRED_TYPE_CLOSURE,warning:UNSAFE_BLOCK_CLOSURE_INFERENCE*/() {
5321 return 1;
5322 });
5323 ''');
5324 var v = mainUnit.topLevelVariables[0];
5325 expect(v.name, 'v');
5326 expect(v.type.toString(), 'List<int>');
5327 }
5328
5329 void test_unsafeBlockClosureInference_methodCall_implicitTypeParam_comment() {
5330 var mainUnit = checkFile('''
5331 class C {
4588 dynamic /*=List<T>*/ f/*<T>*/(dynamic/*=T*/ g()) => <T>[g()]; 5332 dynamic /*=List<T>*/ f/*<T>*/(dynamic/*=T*/ g()) => <T>[g()];
4589 } 5333 }
4590 var v = new C().f( 5334 var v = new C().f(
4591 /*info:INFERRED_TYPE_CLOSURE,warning:UNSAFE_BLOCK_CLOSURE_INFERENCE*/() { 5335 /*info:INFERRED_TYPE_CLOSURE,warning:UNSAFE_BLOCK_CLOSURE_INFERENCE*/() {
4592 return 1; 5336 return 1;
4593 }); 5337 });
4594 '''); 5338 ''');
4595 var v = mainUnit.topLevelVariables[0]; 5339 var v = mainUnit.topLevelVariables[0];
4596 expect(v.name, 'v'); 5340 expect(v.name, 'v');
4597 expect(v.type.toString(), 'List<int>'); 5341 expect(v.type.toString(), 'List<int>');
4598 } 5342 }
4599 5343
4600 void test_unsafeBlockClosureInference_methodCall_noTypeParam() { 5344 void test_unsafeBlockClosureInference_methodCall_noTypeParam() {
4601 var mainUnit = checkFile(''' 5345 var mainUnit = checkFile('''
4602 class C { 5346 class C {
4603 double f(x) => 1.0; 5347 double f(x) => 1.0;
4604 } 5348 }
4605 var v = new C().f(/*info:INFERRED_TYPE_CLOSURE*/() { return 1; }); 5349 var v = new C().f(/*info:INFERRED_TYPE_CLOSURE*/() { return 1; });
4606 '''); 5350 ''');
4607 var v = mainUnit.topLevelVariables[0]; 5351 var v = mainUnit.topLevelVariables[0];
4608 expect(v.name, 'v'); 5352 expect(v.name, 'v');
4609 expect(v.type.toString(), 'double'); 5353 expect(v.type.toString(), 'double');
4610 } 5354 }
4611 5355
4612 void test_voidReturnTypeSubtypesDynamic() { 5356 void test_voidReturnTypeSubtypesDynamic() {
4613 var unit = checkFile(r''' 5357 var unit = checkFile(r'''
5358 T run<T>(T f()) {
5359 print("running");
5360 var t = f();
5361 print("done running");
5362 return t;
5363 }
5364
5365
5366 void printRunning() { print("running"); }
5367 var x = run<dynamic>(printRunning);
5368 var y = run(printRunning);
5369
5370 main() {
5371 void printRunning() { print("running"); }
5372 var x = run<dynamic>(printRunning);
5373 var y = run(printRunning);
5374 x = 123;
5375 x = 'hi';
5376 y = 123;
5377 y = 'hi';
5378 }
5379 ''');
5380
5381 var x = unit.topLevelVariables[0];
5382 var y = unit.topLevelVariables[1];
5383 expect(x.type.toString(), 'dynamic');
5384 expect(y.type.toString(), 'dynamic');
5385 }
5386
5387 void test_voidReturnTypeSubtypesDynamic_comment() {
5388 var unit = checkFile(r'''
4614 /*=T*/ run/*<T>*/(/*=T*/ f()) { 5389 /*=T*/ run/*<T>*/(/*=T*/ f()) {
4615 print("running"); 5390 print("running");
4616 var t = f(); 5391 var t = f();
4617 print("done running"); 5392 print("done running");
4618 return t; 5393 return t;
4619 } 5394 }
4620 5395
4621 5396
4622 void printRunning() { print("running"); } 5397 void printRunning() { print("running"); }
4623 var x = run/*<dynamic>*/(printRunning); 5398 var x = run/*<dynamic>*/(printRunning);
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
4678 } 5453 }
4679 5454
4680 void setUp() { 5455 void setUp() {
4681 helper.doSetUp(); 5456 helper.doSetUp();
4682 } 5457 }
4683 5458
4684 void tearDown() { 5459 void tearDown() {
4685 helper.doTearDown(); 5460 helper.doTearDown();
4686 } 5461 }
4687 } 5462 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698