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

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

Issue 2990383002: Emit a hint when using generic method comment syntax (issue 30356) (Closed)
Patch Set: Created 3 years, 4 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
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 library analyzer.test.src.task.strong.checker_test; 5 library analyzer.test.src.task.strong.checker_test;
6 6
7 import 'package:test_reflective_loader/test_reflective_loader.dart'; 7 import 'package:test_reflective_loader/test_reflective_loader.dart';
8 8
9 import 'strong_test_helper.dart'; 9 import 'strong_test_helper.dart';
10 10
(...skipping 1116 matching lines...) Expand 10 before | Expand all | Expand 10 after
1127 typedef dynamic ATop(A x); 1127 typedef dynamic ATop(A x);
1128 typedef A BotA(dynamic x); 1128 typedef A BotA(dynamic x);
1129 typedef A AA(A x); 1129 typedef A AA(A x);
1130 typedef A TopA(Object x); 1130 typedef A TopA(Object x);
1131 typedef dynamic TopTop(Object x); 1131 typedef dynamic TopTop(Object x);
1132 1132
1133 dynamic aTop(A x) => x; 1133 dynamic aTop(A x) => x;
1134 A aa(A x) => x; 1134 A aa(A x) => x;
1135 dynamic topTop(dynamic x) => x; 1135 dynamic topTop(dynamic x) => x;
1136 A topA(dynamic x) => /*info:DYNAMIC_CAST*/x; 1136 A topA(dynamic x) => /*info:DYNAMIC_CAST*/x;
1137 void apply/*<T>*/(/*=T*/ f0, /*=T*/ f1, /*=T*/ f2, 1137 void apply<T>(T f0, T f1, T f2,
1138 /*=T*/ f3, /*=T*/ f4, /*=T*/ f5) {} 1138 T f3, T f4, T f5) {}
1139 void main() { 1139 void main() {
1140 BotTop botTop; 1140 BotTop botTop;
1141 BotA botA; 1141 BotA botA;
1142 { 1142 {
1143 BotTop f; 1143 BotTop f;
1144 f = topA; 1144 f = topA;
1145 f = topTop; 1145 f = topTop;
1146 f = aa; 1146 f = aa;
1147 f = aTop; 1147 f = aTop;
1148 f = botA; 1148 f = botA;
1149 f = botTop; 1149 f = botTop;
1150 apply/*<BotTop>*/( 1150 apply<BotTop>(
1151 topA, 1151 topA,
1152 topTop, 1152 topTop,
1153 aa, 1153 aa,
1154 aTop, 1154 aTop,
1155 botA, 1155 botA,
1156 botTop 1156 botTop
1157 ); 1157 );
1158 apply/*<BotTop>*/( 1158 apply<BotTop>(
1159 (dynamic x) => new A(), 1159 (dynamic x) => new A(),
1160 (dynamic x) => (x as Object), 1160 (dynamic x) => (x as Object),
1161 (A x) => x, 1161 (A x) => x,
1162 (A x) => null, 1162 (A x) => null,
1163 botA, 1163 botA,
1164 botTop 1164 botTop
1165 ); 1165 );
1166 } 1166 }
1167 { 1167 {
1168 ATop f; 1168 ATop f;
1169 f = topA; 1169 f = topA;
1170 f = topTop; 1170 f = topTop;
1171 f = aa; 1171 f = aa;
1172 f = aTop; 1172 f = aTop;
1173 f = /*error:INVALID_ASSIGNMENT*/botA; 1173 f = /*error:INVALID_ASSIGNMENT*/botA;
1174 f = /*info:DOWN_CAST_COMPOSITE*/botTop; 1174 f = /*info:DOWN_CAST_COMPOSITE*/botTop;
1175 apply/*<ATop>*/( 1175 apply<ATop>(
1176 topA, 1176 topA,
1177 topTop, 1177 topTop,
1178 aa, 1178 aa,
1179 aTop, 1179 aTop,
1180 /*error:ARGUMENT_TYPE_NOT_ASSIGNABLE*/botA, 1180 /*error:ARGUMENT_TYPE_NOT_ASSIGNABLE*/botA,
1181 /*info:DOWN_CAST_COMPOSITE*/botTop 1181 /*info:DOWN_CAST_COMPOSITE*/botTop
1182 ); 1182 );
1183 apply/*<ATop>*/( 1183 apply<ATop>(
1184 (dynamic x) => new A(), 1184 (dynamic x) => new A(),
1185 (dynamic x) => (x as Object), 1185 (dynamic x) => (x as Object),
1186 (A x) => x, 1186 (A x) => x,
1187 (A x) => null, 1187 (A x) => null,
1188 /*error:ARGUMENT_TYPE_NOT_ASSIGNABLE*/botA, 1188 /*error:ARGUMENT_TYPE_NOT_ASSIGNABLE*/botA,
1189 /*info:DOWN_CAST_COMPOSITE*/botTop 1189 /*info:DOWN_CAST_COMPOSITE*/botTop
1190 ); 1190 );
1191 } 1191 }
1192 { 1192 {
1193 BotA f; 1193 BotA f;
1194 f = topA; 1194 f = topA;
1195 f = /*error:INVALID_ASSIGNMENT*/topTop; 1195 f = /*error:INVALID_ASSIGNMENT*/topTop;
1196 f = aa; 1196 f = aa;
1197 f = /*error:INVALID_ASSIGNMENT*/aTop; 1197 f = /*error:INVALID_ASSIGNMENT*/aTop;
1198 f = botA; 1198 f = botA;
1199 f = /*info:DOWN_CAST_COMPOSITE*/botTop; 1199 f = /*info:DOWN_CAST_COMPOSITE*/botTop;
1200 apply/*<BotA>*/( 1200 apply<BotA>(
1201 topA, 1201 topA,
1202 /*error:ARGUMENT_TYPE_NOT_ASSIGNABLE*/topTop, 1202 /*error:ARGUMENT_TYPE_NOT_ASSIGNABLE*/topTop,
1203 aa, 1203 aa,
1204 /*error:ARGUMENT_TYPE_NOT_ASSIGNABLE*/aTop, 1204 /*error:ARGUMENT_TYPE_NOT_ASSIGNABLE*/aTop,
1205 botA, 1205 botA,
1206 /*info:DOWN_CAST_COMPOSITE*/botTop 1206 /*info:DOWN_CAST_COMPOSITE*/botTop
1207 ); 1207 );
1208 apply/*<BotA>*/( 1208 apply<BotA>(
1209 (dynamic x) => new A(), 1209 (dynamic x) => new A(),
1210 /*error:ARGUMENT_TYPE_NOT_ASSIGNABLE*/(dynamic x) => (x as Object), 1210 /*error:ARGUMENT_TYPE_NOT_ASSIGNABLE*/(dynamic x) => (x as Object),
1211 (A x) => x, 1211 (A x) => x,
1212 /*error:ARGUMENT_TYPE_NOT_ASSIGNABLE*/(A x) => (/*info:UNNECESSARY_CAST* /x as Object), 1212 /*error:ARGUMENT_TYPE_NOT_ASSIGNABLE*/(A x) => (/*info:UNNECESSARY_CAST* /x as Object),
1213 botA, 1213 botA,
1214 /*info:DOWN_CAST_COMPOSITE*/botTop 1214 /*info:DOWN_CAST_COMPOSITE*/botTop
1215 ); 1215 );
1216 } 1216 }
1217 { 1217 {
1218 AA f; 1218 AA f;
1219 f = topA; 1219 f = topA;
1220 f = /*error:INVALID_ASSIGNMENT*/topTop; 1220 f = /*error:INVALID_ASSIGNMENT*/topTop;
1221 f = aa; 1221 f = aa;
1222 f = /*error:INVALID_CAST_FUNCTION*/aTop; // known function 1222 f = /*error:INVALID_CAST_FUNCTION*/aTop; // known function
1223 f = /*info:DOWN_CAST_COMPOSITE*/botA; 1223 f = /*info:DOWN_CAST_COMPOSITE*/botA;
1224 f = /*info:DOWN_CAST_COMPOSITE*/botTop; 1224 f = /*info:DOWN_CAST_COMPOSITE*/botTop;
1225 apply/*<AA>*/( 1225 apply<AA>(
1226 topA, 1226 topA,
1227 /*error:ARGUMENT_TYPE_NOT_ASSIGNABLE*/topTop, 1227 /*error:ARGUMENT_TYPE_NOT_ASSIGNABLE*/topTop,
1228 aa, 1228 aa,
1229 /*error:INVALID_CAST_FUNCTION*/aTop, // known function 1229 /*error:INVALID_CAST_FUNCTION*/aTop, // known function
1230 /*info:DOWN_CAST_COMPOSITE*/botA, 1230 /*info:DOWN_CAST_COMPOSITE*/botA,
1231 /*info:DOWN_CAST_COMPOSITE*/botTop 1231 /*info:DOWN_CAST_COMPOSITE*/botTop
1232 ); 1232 );
1233 apply/*<AA>*/( 1233 apply<AA>(
1234 (dynamic x) => new A(), 1234 (dynamic x) => new A(),
1235 /*error:ARGUMENT_TYPE_NOT_ASSIGNABLE*/(dynamic x) => (x as Object), 1235 /*error:ARGUMENT_TYPE_NOT_ASSIGNABLE*/(dynamic x) => (x as Object),
1236 (A x) => x, 1236 (A x) => x,
1237 /*error:INVALID_CAST_FUNCTION_EXPR*/(A x) => (/*info:UNNECESSARY_CAST*/x as Object), // known function 1237 /*error:INVALID_CAST_FUNCTION_EXPR*/(A x) => (/*info:UNNECESSARY_CAST*/x as Object), // known function
1238 /*info:DOWN_CAST_COMPOSITE*/botA, 1238 /*info:DOWN_CAST_COMPOSITE*/botA,
1239 /*info:DOWN_CAST_COMPOSITE*/botTop 1239 /*info:DOWN_CAST_COMPOSITE*/botTop
1240 ); 1240 );
1241 } 1241 }
1242 { 1242 {
1243 TopTop f; 1243 TopTop f;
1244 f = topA; 1244 f = topA;
1245 f = topTop; 1245 f = topTop;
1246 f = /*error:INVALID_ASSIGNMENT*/aa; 1246 f = /*error:INVALID_ASSIGNMENT*/aa;
1247 f = /*error:INVALID_CAST_FUNCTION*/aTop; // known function 1247 f = /*error:INVALID_CAST_FUNCTION*/aTop; // known function
1248 f = /*error:INVALID_ASSIGNMENT*/botA; 1248 f = /*error:INVALID_ASSIGNMENT*/botA;
1249 f = /*info:DOWN_CAST_COMPOSITE*/botTop; 1249 f = /*info:DOWN_CAST_COMPOSITE*/botTop;
1250 apply/*<TopTop>*/( 1250 apply<TopTop>(
1251 topA, 1251 topA,
1252 topTop, 1252 topTop,
1253 /*error:ARGUMENT_TYPE_NOT_ASSIGNABLE*/aa, 1253 /*error:ARGUMENT_TYPE_NOT_ASSIGNABLE*/aa,
1254 /*error:INVALID_CAST_FUNCTION*/aTop, // known function 1254 /*error:INVALID_CAST_FUNCTION*/aTop, // known function
1255 /*error:ARGUMENT_TYPE_NOT_ASSIGNABLE*/botA, 1255 /*error:ARGUMENT_TYPE_NOT_ASSIGNABLE*/botA,
1256 /*info:DOWN_CAST_COMPOSITE*/botTop 1256 /*info:DOWN_CAST_COMPOSITE*/botTop
1257 ); 1257 );
1258 apply/*<TopTop>*/( 1258 apply<TopTop>(
1259 (dynamic x) => new A(), 1259 (dynamic x) => new A(),
1260 (dynamic x) => (x as Object), 1260 (dynamic x) => (x as Object),
1261 /*error:ARGUMENT_TYPE_NOT_ASSIGNABLE*/(A x) => x, 1261 /*error:ARGUMENT_TYPE_NOT_ASSIGNABLE*/(A x) => x,
1262 /*error:INVALID_CAST_FUNCTION_EXPR*/(A x) => (/*info:UNNECESSARY_CAST*/x as Object), // known function 1262 /*error:INVALID_CAST_FUNCTION_EXPR*/(A x) => (/*info:UNNECESSARY_CAST*/x as Object), // known function
1263 /*error:ARGUMENT_TYPE_NOT_ASSIGNABLE*/botA, 1263 /*error:ARGUMENT_TYPE_NOT_ASSIGNABLE*/botA,
1264 /*info:DOWN_CAST_COMPOSITE*/botTop 1264 /*info:DOWN_CAST_COMPOSITE*/botTop
1265 ); 1265 );
1266 } 1266 }
1267 { 1267 {
1268 TopA f; 1268 TopA f;
1269 f = topA; 1269 f = topA;
1270 f = /*error:INVALID_CAST_FUNCTION*/topTop; // known function 1270 f = /*error:INVALID_CAST_FUNCTION*/topTop; // known function
1271 f = /*error:INVALID_CAST_FUNCTION*/aa; // known function 1271 f = /*error:INVALID_CAST_FUNCTION*/aa; // known function
1272 f = /*error:INVALID_CAST_FUNCTION*/aTop; // known function 1272 f = /*error:INVALID_CAST_FUNCTION*/aTop; // known function
1273 f = /*info:DOWN_CAST_COMPOSITE*/botA; 1273 f = /*info:DOWN_CAST_COMPOSITE*/botA;
1274 f = /*info:DOWN_CAST_COMPOSITE*/botTop; 1274 f = /*info:DOWN_CAST_COMPOSITE*/botTop;
1275 apply/*<TopA>*/( 1275 apply<TopA>(
1276 topA, 1276 topA,
1277 /*error:INVALID_CAST_FUNCTION*/topTop, // known function 1277 /*error:INVALID_CAST_FUNCTION*/topTop, // known function
1278 /*error:INVALID_CAST_FUNCTION*/aa, // known function 1278 /*error:INVALID_CAST_FUNCTION*/aa, // known function
1279 /*error:INVALID_CAST_FUNCTION*/aTop, // known function 1279 /*error:INVALID_CAST_FUNCTION*/aTop, // known function
1280 /*info:DOWN_CAST_COMPOSITE*/botA, 1280 /*info:DOWN_CAST_COMPOSITE*/botA,
1281 /*info:DOWN_CAST_COMPOSITE*/botTop 1281 /*info:DOWN_CAST_COMPOSITE*/botTop
1282 ); 1282 );
1283 apply/*<TopA>*/( 1283 apply<TopA>(
1284 (dynamic x) => new A(), 1284 (dynamic x) => new A(),
1285 /*error:INVALID_CAST_FUNCTION_EXPR*/(dynamic x) => (x as Object), // kno wn function 1285 /*error:INVALID_CAST_FUNCTION_EXPR*/(dynamic x) => (x as Object), // kno wn function
1286 /*error:INVALID_CAST_FUNCTION_EXPR*/(A x) => x, // known function 1286 /*error:INVALID_CAST_FUNCTION_EXPR*/(A x) => x, // known function
1287 /*error:INVALID_CAST_FUNCTION_EXPR*/(A x) => (/*info:UNNECESSARY_CAST*/x as Object), // known function 1287 /*error:INVALID_CAST_FUNCTION_EXPR*/(A x) => (/*info:UNNECESSARY_CAST*/x as Object), // known function
1288 /*info:DOWN_CAST_COMPOSITE*/botA, 1288 /*info:DOWN_CAST_COMPOSITE*/botA,
1289 /*info:DOWN_CAST_COMPOSITE*/botTop 1289 /*info:DOWN_CAST_COMPOSITE*/botTop
1290 ); 1290 );
1291 } 1291 }
1292 } 1292 }
1293 '''); 1293 ''');
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
1348 new A(new Callable()); 1348 new A(new Callable());
1349 } 1349 }
1350 1350
1351 void test1() { 1351 void test1() {
1352 void takesF(f(int x)) => null; 1352 void takesF(f(int x)) => null;
1353 takesF((dynamic y) => 3); 1353 takesF((dynamic y) => 3);
1354 } 1354 }
1355 1355
1356 void test2() { 1356 void test2() {
1357 int x; 1357 int x;
1358 int f/*<T>*/(/*=T*/ t, callback(/*=T*/ x)) { return 3; } 1358 int f<T>(T t, callback(T x)) { return 3; }
1359 f(x, (y) => 3); 1359 f(x, (y) => 3);
1360 } 1360 }
1361 '''); 1361 ''');
1362 } 1362 }
1363 1363
1364 test_functionTypingAndSubtyping_functionLiteralVariance() async { 1364 test_functionTypingAndSubtyping_functionLiteralVariance() async {
1365 await checkFile(''' 1365 await checkFile('''
1366 class A {} 1366 class A {}
1367 class B extends A {} 1367 class B extends A {}
1368 1368
(...skipping 593 matching lines...) Expand 10 before | Expand all | Expand 10 after
1962 } 1962 }
1963 } 1963 }
1964 '''); 1964 ''');
1965 } 1965 }
1966 1966
1967 test_functionTypingAndSubtyping_subtypeOfUniversalType() async { 1967 test_functionTypingAndSubtyping_subtypeOfUniversalType() async {
1968 await checkFile(''' 1968 await checkFile('''
1969 void main() { 1969 void main() {
1970 nonGenericFn(x) => null; 1970 nonGenericFn(x) => null;
1971 { 1971 {
1972 /*=R*/ f/*<P, R>*/(/*=P*/ p) => null; 1972 R f<P, R>(P p) => null;
1973 /*=T*/ g/*<S, T>*/(/*=S*/ s) => null; 1973 T g<S, T>(S s) => null;
1974 1974
1975 var local = f; 1975 var local = f;
1976 local = g; // valid 1976 local = g; // valid
1977 1977
1978 // Non-generic function cannot subtype a generic one. 1978 // Non-generic function cannot subtype a generic one.
1979 local = /*error:INVALID_ASSIGNMENT*/(x) => null; 1979 local = /*error:INVALID_ASSIGNMENT*/(x) => null;
1980 local = /*error:INVALID_ASSIGNMENT*/nonGenericFn; 1980 local = /*error:INVALID_ASSIGNMENT*/nonGenericFn;
1981 } 1981 }
1982 { 1982 {
1983 Iterable/*<R>*/ f/*<P, R>*/(List/*<P>*/ p) => null; 1983 Iterable<R> f<P, R>(List<P> p) => null;
1984 List/*<T>*/ g/*<S, T>*/(Iterable/*<S>*/ s) => null; 1984 List<T> g<S, T>(Iterable<S> s) => null;
1985 1985
1986 var local = f; 1986 var local = f;
1987 local = g; // valid 1987 local = g; // valid
1988 1988
1989 var local2 = g; 1989 var local2 = g;
1990 local = local2; 1990 local = local2;
1991 local2 = /*error:INVALID_CAST_FUNCTION*/f; 1991 local2 = /*error:INVALID_CAST_FUNCTION*/f;
1992 local2 = /*info:DOWN_CAST_COMPOSITE*/local; 1992 local2 = /*info:DOWN_CAST_COMPOSITE*/local;
1993 1993
1994 // Non-generic function cannot subtype a generic one. 1994 // Non-generic function cannot subtype a generic one.
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
2032 } 2032 }
2033 2033
2034 class Derived2<S extends B> extends Base<B> { 2034 class Derived2<S extends B> extends Base<B> {
2035 S foo() => null; 2035 S foo() => null;
2036 } 2036 }
2037 '''); 2037 ''');
2038 } 2038 }
2039 2039
2040 test_genericFunctionWrongNumberOfArguments() async { 2040 test_genericFunctionWrongNumberOfArguments() async {
2041 await checkFile(r''' 2041 await checkFile(r'''
2042 /*=T*/ foo/*<T>*/(/*=T*/ x, /*=T*/ y) => x; 2042 T foo<T>(T x, T y) => x;
2043 /*=T*/ bar/*<T>*/({/*=T*/ x, /*=T*/ y}) => x; 2043 T bar<T>({T x, T y}) => x;
2044 2044
2045 main() { 2045 main() {
2046 String x; 2046 String x;
2047 // resolving these shouldn't crash. 2047 // resolving these shouldn't crash.
2048 foo/*error:EXTRA_POSITIONAL_ARGUMENTS*/(1, 2, 3); 2048 foo/*error:EXTRA_POSITIONAL_ARGUMENTS*/(1, 2, 3);
2049 x = foo/*error:EXTRA_POSITIONAL_ARGUMENTS*/('1', '2', '3'); 2049 x = foo/*error:EXTRA_POSITIONAL_ARGUMENTS*/('1', '2', '3');
2050 foo/*error:NOT_ENOUGH_REQUIRED_ARGUMENTS*/(1); 2050 foo/*error:NOT_ENOUGH_REQUIRED_ARGUMENTS*/(1);
2051 x = foo/*error:NOT_ENOUGH_REQUIRED_ARGUMENTS*/('1'); 2051 x = foo/*error:NOT_ENOUGH_REQUIRED_ARGUMENTS*/('1');
2052 x = foo/*error:EXTRA_POSITIONAL_ARGUMENTS*/(/*error:ARGUMENT_TYPE_NOT_ASSIGNAB LE*/1, /*error:ARGUMENT_TYPE_NOT_ASSIGNABLE*/2, 3); 2052 x = foo/*error:EXTRA_POSITIONAL_ARGUMENTS*/(/*error:ARGUMENT_TYPE_NOT_ASSIGNAB LE*/1, /*error:ARGUMENT_TYPE_NOT_ASSIGNABLE*/2, 3);
2053 x = foo/*error:NOT_ENOUGH_REQUIRED_ARGUMENTS*/(/*error:ARGUMENT_TYPE_NOT_ASSIG NABLE*/1); 2053 x = foo/*error:NOT_ENOUGH_REQUIRED_ARGUMENTS*/(/*error:ARGUMENT_TYPE_NOT_ASSIG NABLE*/1);
2054 2054
2055 // named arguments 2055 // named arguments
2056 bar(y: 1, x: 2, /*error:UNDEFINED_NAMED_PARAMETER*/z: 3); 2056 bar(y: 1, x: 2, /*error:UNDEFINED_NAMED_PARAMETER*/z: 3);
2057 x = bar(/*error:UNDEFINED_NAMED_PARAMETER*/z: '1', x: '2', y: '3'); 2057 x = bar(/*error:UNDEFINED_NAMED_PARAMETER*/z: '1', x: '2', y: '3');
2058 bar(y: 1); 2058 bar(y: 1);
2059 x = bar(x: '1', /*error:UNDEFINED_NAMED_PARAMETER*/z: 42); 2059 x = bar(x: '1', /*error:UNDEFINED_NAMED_PARAMETER*/z: 42);
2060 x = bar(/*error:ARGUMENT_TYPE_NOT_ASSIGNABLE*/y: 1, /*error:ARGUMENT_TYPE_NOT_ ASSIGNABLE*/x: 2, /*error:UNDEFINED_NAMED_PARAMETER*/z: 3); 2060 x = bar(/*error:ARGUMENT_TYPE_NOT_ASSIGNABLE*/y: 1, /*error:ARGUMENT_TYPE_NOT_ ASSIGNABLE*/x: 2, /*error:UNDEFINED_NAMED_PARAMETER*/z: 3);
2061 x = bar(/*error:ARGUMENT_TYPE_NOT_ASSIGNABLE*/x: 1); 2061 x = bar(/*error:ARGUMENT_TYPE_NOT_ASSIGNABLE*/x: 1);
2062 } 2062 }
2063 '''); 2063 ''');
2064 } 2064 }
2065 2065
2066 test_genericMethodOverride() async { 2066 test_genericMethodOverride() async {
2067 await checkFile(''' 2067 await checkFile('''
2068 class Future<T> { 2068 class Future<T> {
2069 /*=S*/ then/*<S>*/(/*=S*/ onValue(T t)) => null; 2069 S then<S>(S onValue(T t)) => null;
2070 } 2070 }
2071 2071
2072 class DerivedFuture<T> extends Future<T> { 2072 class DerivedFuture<T> extends Future<T> {
2073 /*=S*/ then/*<S>*/(/*=S*/ onValue(T t)) => null; 2073 S then<S>(S onValue(T t)) => null;
2074 } 2074 }
2075 2075
2076 class DerivedFuture2<A> extends Future<A> { 2076 class DerivedFuture2<A> extends Future<A> {
2077 /*=B*/ then/*<B>*/(/*=B*/ onValue(A a)) => null; 2077 B then<B>(B onValue(A a)) => null;
2078 } 2078 }
2079 2079
2080 class DerivedFuture3<T> extends Future<T> { 2080 class DerivedFuture3<T> extends Future<T> {
2081 /*=S*/ then/*<S>*/(Object onValue(T t)) => null; 2081 S then<S>(Object onValue(T t)) => null;
2082 } 2082 }
2083 2083
2084 class DerivedFuture4<A> extends Future<A> { 2084 class DerivedFuture4<A> extends Future<A> {
2085 /*=B*/ then/*<B>*/(Object onValue(A a)) => null; 2085 B then<B>(Object onValue(A a)) => null;
2086 } 2086 }
2087 '''); 2087 ''');
2088 } 2088 }
2089 2089
2090 test_genericMethodSuper() async { 2090 test_genericMethodSuper() async {
2091 await checkFile(r''' 2091 await checkFile(r'''
2092 class A<T> { 2092 class A<T> {
2093 A<S> create<S extends T>() => new A<S>(); 2093 A<S> create<S extends T>() => new A<S>();
2094 } 2094 }
2095 class B extends A { 2095 class B extends A {
(...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after
2370 /*error:IMPLICIT_DYNAMIC_FIELD*/x4; 2370 /*error:IMPLICIT_DYNAMIC_FIELD*/x4;
2371 dynamic y0; 2371 dynamic y0;
2372 dynamic y1 = (<dynamic>[])[0]; 2372 dynamic y1 = (<dynamic>[])[0];
2373 } 2373 }
2374 '''); 2374 ''');
2375 await check(implicitDynamic: false); 2375 await check(implicitDynamic: false);
2376 } 2376 }
2377 2377
2378 test_implicitDynamic_function() async { 2378 test_implicitDynamic_function() async {
2379 addFile(r''' 2379 addFile(r'''
2380 /*=T*/ a/*<T>*/(/*=T*/ t) => t; 2380 T a<T>(T t) => t;
2381 /*=T*/ b/*<T>*/() => null; 2381 T b<T>() => null;
2382 2382
2383 void main/*<S>*/() { 2383 void main<S>() {
2384 dynamic d; 2384 dynamic d;
2385 int i; 2385 int i;
2386 /*error:IMPLICIT_DYNAMIC_FUNCTION*/a(d); 2386 /*error:IMPLICIT_DYNAMIC_FUNCTION*/a(d);
2387 a(42); 2387 a(42);
2388 /*error:IMPLICIT_DYNAMIC_FUNCTION*/b(); 2388 /*error:IMPLICIT_DYNAMIC_FUNCTION*/b();
2389 d = /*error:IMPLICIT_DYNAMIC_FUNCTION*/b(); 2389 d = /*error:IMPLICIT_DYNAMIC_FUNCTION*/b();
2390 i = b(); 2390 i = b();
2391 2391
2392 void f/*<T>*/(/*=T*/ t) {}; 2392 void f<T>(T t) {};
2393 /*=T*/ g/*<T>*/() => null; 2393 T g<T>() => null;
2394 2394
2395 /*error:IMPLICIT_DYNAMIC_FUNCTION*/f(d); 2395 /*error:IMPLICIT_DYNAMIC_FUNCTION*/f(d);
2396 f(42); 2396 f(42);
2397 /*error:IMPLICIT_DYNAMIC_FUNCTION*/g(); 2397 /*error:IMPLICIT_DYNAMIC_FUNCTION*/g();
2398 d = /*error:IMPLICIT_DYNAMIC_FUNCTION*/g(); 2398 d = /*error:IMPLICIT_DYNAMIC_FUNCTION*/g();
2399 i = g(); 2399 i = g();
2400 2400
2401 /*error:IMPLICIT_DYNAMIC_INVOKE*/(/*<T>*/(/*=T*/ t) => t)(d); 2401 /*error:IMPLICIT_DYNAMIC_INVOKE*/(<T>(T t) => t)(d);
2402 (/*<T>*/(/*=T*/ t) => t)(42); 2402 (<T>(T t) => t)(42);
2403 (/*<T>*/() => /*info:UNNECESSARY_CAST*/null as dynamic/*=T*/)/*<int>*/(); 2403 (<T>() => /*info:UNNECESSARY_CAST*/null as T)<int>();
2404 } 2404 }
2405 '''); 2405 ''');
2406 await check(implicitDynamic: false); 2406 await check(implicitDynamic: false);
2407 } 2407 }
2408 2408
2409 test_implicitDynamic_listLiteral() async { 2409 test_implicitDynamic_listLiteral() async {
2410 addFile(r''' 2410 addFile(r'''
2411 2411
2412 var l0 = /*error:IMPLICIT_DYNAMIC_LIST_LITERAL*/[]; 2412 var l0 = /*error:IMPLICIT_DYNAMIC_LIST_LITERAL*/[];
2413 List l1 = /*error:IMPLICIT_DYNAMIC_LIST_LITERAL*/[]; 2413 List l1 = /*error:IMPLICIT_DYNAMIC_LIST_LITERAL*/[];
(...skipping 23 matching lines...) Expand all
2437 var m7 = <String, String>{}; 2437 var m7 = <String, String>{};
2438 Map<String, String> m8 = /*info:INFERRED_TYPE_LITERAL*/{}; 2438 Map<String, String> m8 = /*info:INFERRED_TYPE_LITERAL*/{};
2439 var m9 = /*info:INFERRED_TYPE_LITERAL*/{'hi': 'there'}; 2439 var m9 = /*info:INFERRED_TYPE_LITERAL*/{'hi': 'there'};
2440 '''); 2440 ''');
2441 await check(implicitDynamic: false); 2441 await check(implicitDynamic: false);
2442 } 2442 }
2443 2443
2444 test_implicitDynamic_method() async { 2444 test_implicitDynamic_method() async {
2445 addFile(r''' 2445 addFile(r'''
2446 class C { 2446 class C {
2447 /*=T*/ m/*<T>*/(/*=T*/ s) => s; 2447 T m<T>(T s) => s;
2448 /*=T*/ n/*<T>*/() => null; 2448 T n<T>() => null;
2449 } 2449 }
2450 class D<E> { 2450 class D<E> {
2451 /*=T*/ m/*<T>*/(/*=T*/ s) => s; 2451 T m<T>(T s) => s;
2452 /*=T*/ n/*<T>*/() => null; 2452 T n<T>() => null;
2453 } 2453 }
2454 void f() { 2454 void f() {
2455 dynamic d; 2455 dynamic d;
2456 int i; 2456 int i;
2457 new C()./*error:IMPLICIT_DYNAMIC_METHOD*/m(d); 2457 new C()./*error:IMPLICIT_DYNAMIC_METHOD*/m(d);
2458 new C().m(42); 2458 new C().m(42);
2459 new C()./*error:IMPLICIT_DYNAMIC_METHOD*/n(); 2459 new C()./*error:IMPLICIT_DYNAMIC_METHOD*/n();
2460 d = new C()./*error:IMPLICIT_DYNAMIC_METHOD*/n(); 2460 d = new C()./*error:IMPLICIT_DYNAMIC_METHOD*/n();
2461 i = new C().n(); 2461 i = new C().n();
2462 2462
(...skipping 1677 matching lines...) Expand 10 before | Expand all | Expand 10 after
4140 } 4140 }
4141 } 4141 }
4142 '''); 4142 ''');
4143 } 4143 }
4144 4144
4145 test_typePromotionFromTypeParameter() async { 4145 test_typePromotionFromTypeParameter() async {
4146 // Regression test for: 4146 // Regression test for:
4147 // https://github.com/dart-lang/sdk/issues/26965 4147 // https://github.com/dart-lang/sdk/issues/26965
4148 // https://github.com/dart-lang/sdk/issues/27040 4148 // https://github.com/dart-lang/sdk/issues/27040
4149 await checkFile(r''' 4149 await checkFile(r'''
4150 void f/*<T>*/(/*=T*/ object) { 4150 void f<T>(T object) {
4151 if (object is String) print(object.substring(1)); 4151 if (object is String) print(object.substring(1));
4152 } 4152 }
4153 void g/*<T extends num>*/(/*=T*/ object) { 4153 void g<T extends num>(T object) {
4154 if (object is int) print(object.isEven); 4154 if (object is int) print(object.isEven);
4155 if (object is String) print(/*info:DYNAMIC_INVOKE*/object./*error:UNDEFINED_ME THOD*/substring(1)); 4155 if (object is String) print(/*info:DYNAMIC_INVOKE*/object./*error:UNDEFINED_ME THOD*/substring(1));
4156 } 4156 }
4157 class Clonable<T> {} 4157 class Clonable<T> {}
4158 class SubClonable<T> extends Clonable<T> { 4158 class SubClonable<T> extends Clonable<T> {
4159 T m(T t) => t; 4159 T m(T t) => t;
4160 } 4160 }
4161 void takesSubClonable/*<A>*/(SubClonable/*<A>*/ t) {} 4161 void takesSubClonable<A>(SubClonable<A> t) {}
4162 4162
4163 void h/*<T extends Clonable<T>>*/(/*=T*/ object) { 4163 void h<T extends Clonable<T>>(T object) {
4164 if (/*info:NON_GROUND_TYPE_CHECK_INFO*/object is SubClonable/*<T>*/) { 4164 if (/*info:NON_GROUND_TYPE_CHECK_INFO*/object is SubClonable<T>) {
4165 print(object.m(object)); 4165 print(object.m(object));
4166 4166
4167 SubClonable/*<T>*/ s = object; 4167 SubClonable<T> s = object;
4168 takesSubClonable/*<T>*/(object); 4168 takesSubClonable<T>(object);
4169 h(object); 4169 h(object);
4170 } 4170 }
4171 } 4171 }
4172 '''); 4172 ''');
4173 } 4173 }
4174 4174
4175 test_typePromotionFromTypeParameterAndInference() async { 4175 test_typePromotionFromTypeParameterAndInference() async {
4176 // Regression test for: 4176 // Regression test for:
4177 // https://github.com/dart-lang/sdk/issues/27040 4177 // https://github.com/dart-lang/sdk/issues/27040
4178 await checkFile(r''' 4178 await checkFile(r'''
4179 void f/*<T extends num>*/(T x, T y) { 4179 void f<T extends num>(T x, T y) {
4180 var z = x; 4180 var z = x;
4181 var f = () => x; 4181 var f = () => x;
4182 f = () => y; 4182 f = () => y;
4183 if (x is int) { 4183 if (x is int) {
4184 /*info:DYNAMIC_INVOKE*/z./*error:UNDEFINED_GETTER*/isEven; 4184 /*info:DYNAMIC_INVOKE*/z./*error:UNDEFINED_GETTER*/isEven;
4185 var q = x; 4185 var q = x;
4186 q = /*info:DOWN_CAST_COMPOSITE*/z; 4186 q = /*info:DOWN_CAST_COMPOSITE*/z;
4187 /*info:DYNAMIC_INVOKE*/f()./*error:UNDEFINED_GETTER*/isEven; 4187 /*info:DYNAMIC_INVOKE*/f()./*error:UNDEFINED_GETTER*/isEven;
4188 4188
4189 // This captures the type `T extends int`. 4189 // This captures the type `T extends int`.
(...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after
4458 class CheckerTest_Driver extends CheckerTest { 4458 class CheckerTest_Driver extends CheckerTest {
4459 @override 4459 @override
4460 bool get enableNewAnalysisDriver => true; 4460 bool get enableNewAnalysisDriver => true;
4461 4461
4462 @failingTest 4462 @failingTest
4463 @override 4463 @override
4464 test_covariantOverride_fields() async { 4464 test_covariantOverride_fields() async {
4465 await super.test_covariantOverride_fields(); 4465 await super.test_covariantOverride_fields();
4466 } 4466 }
4467 } 4467 }
OLDNEW
« no previous file with comments | « pkg/analyzer/test/generated/strong_mode_test.dart ('k') | pkg/analyzer/test/src/task/strong/inferred_type_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698