| OLD | NEW |
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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.generated.resolver_test; | 5 library analyzer.test.generated.resolver_test; |
| 6 | 6 |
| 7 import 'dart:collection'; | 7 import 'dart:collection'; |
| 8 | 8 |
| 9 import 'package:analyzer/dart/ast/ast.dart'; | 9 import 'package:analyzer/dart/ast/ast.dart'; |
| 10 import 'package:analyzer/dart/ast/visitor.dart'; | 10 import 'package:analyzer/dart/ast/visitor.dart'; |
| (...skipping 2365 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2376 abstract class Iter { | 2376 abstract class Iter { |
| 2377 List<S> map<S>(S f(x)); | 2377 List<S> map<S>(S f(x)); |
| 2378 } | 2378 } |
| 2379 class C {} | 2379 class C {} |
| 2380 C toSpan(dynamic element) { | 2380 C toSpan(dynamic element) { |
| 2381 if (element is Iter) { | 2381 if (element is Iter) { |
| 2382 var y = element.map(toSpan); | 2382 var y = element.map(toSpan); |
| 2383 } | 2383 } |
| 2384 return null; | 2384 return null; |
| 2385 }'''); | 2385 }'''); |
| 2386 SimpleIdentifier y = _findIdentifier('y = '); | 2386 _expectIdentifierType('y = ', 'dynamic', 'List<dynamic>'); |
| 2387 expect(y.staticType.toString(), 'dynamic'); | |
| 2388 expect(y.propagatedType.toString(), 'List<dynamic>'); | |
| 2389 } | 2387 } |
| 2390 } | 2388 } |
| 2391 | 2389 |
| 2392 @reflectiveTest | 2390 @reflectiveTest |
| 2393 class HintCodeTest extends ResolverTestCase { | 2391 class HintCodeTest extends ResolverTestCase { |
| 2394 void fail_deadCode_statementAfterRehrow() { | 2392 void fail_deadCode_statementAfterRehrow() { |
| 2395 Source source = addSource(r''' | 2393 Source source = addSource(r''' |
| 2396 f() { | 2394 f() { |
| 2397 try { | 2395 try { |
| 2398 var one = 1; | 2396 var one = 1; |
| (...skipping 7735 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 10134 */ | 10132 */ |
| 10135 @reflectiveTest | 10133 @reflectiveTest |
| 10136 class StaticTypeAnalyzer2Test extends _StaticTypeAnalyzer2TestShared { | 10134 class StaticTypeAnalyzer2Test extends _StaticTypeAnalyzer2TestShared { |
| 10137 void test_FunctionExpressionInvocation_block() { | 10135 void test_FunctionExpressionInvocation_block() { |
| 10138 String code = r''' | 10136 String code = r''' |
| 10139 main() { | 10137 main() { |
| 10140 var foo = (() { return 1; })(); | 10138 var foo = (() { return 1; })(); |
| 10141 } | 10139 } |
| 10142 '''; | 10140 '''; |
| 10143 _resolveTestUnit(code); | 10141 _resolveTestUnit(code); |
| 10144 SimpleIdentifier identifier = _findIdentifier('foo'); | 10142 _expectInitializerType('foo', 'dynamic', isNull); |
| 10145 VariableDeclaration declaration = | |
| 10146 identifier.getAncestor((node) => node is VariableDeclaration); | |
| 10147 expect(declaration.initializer.staticType.isDynamic, isTrue); | |
| 10148 expect(declaration.initializer.propagatedType, isNull); | |
| 10149 } | 10143 } |
| 10150 | 10144 |
| 10151 void test_FunctionExpressionInvocation_curried() { | 10145 void test_FunctionExpressionInvocation_curried() { |
| 10152 String code = r''' | 10146 String code = r''' |
| 10153 typedef int F(); | 10147 typedef int F(); |
| 10154 F f() => null; | 10148 F f() => null; |
| 10155 main() { | 10149 main() { |
| 10156 var foo = f()(); | 10150 var foo = f()(); |
| 10157 } | 10151 } |
| 10158 '''; | 10152 '''; |
| 10159 _resolveTestUnit(code); | 10153 _resolveTestUnit(code); |
| 10160 SimpleIdentifier identifier = _findIdentifier('foo'); | 10154 _expectInitializerType('foo', 'int', isNull); |
| 10161 VariableDeclaration declaration = | |
| 10162 identifier.getAncestor((node) => node is VariableDeclaration); | |
| 10163 expect(declaration.initializer.staticType.name, 'int'); | |
| 10164 expect(declaration.initializer.propagatedType, isNull); | |
| 10165 } | 10155 } |
| 10166 | 10156 |
| 10167 void test_FunctionExpressionInvocation_expression() { | 10157 void test_FunctionExpressionInvocation_expression() { |
| 10168 String code = r''' | 10158 String code = r''' |
| 10169 main() { | 10159 main() { |
| 10170 var foo = (() => 1)(); | 10160 var foo = (() => 1)(); |
| 10171 } | 10161 } |
| 10172 '''; | 10162 '''; |
| 10173 _resolveTestUnit(code); | 10163 _resolveTestUnit(code); |
| 10174 SimpleIdentifier identifier = _findIdentifier('foo'); | 10164 _expectInitializerType('foo', 'int', isNull); |
| 10175 VariableDeclaration declaration = | |
| 10176 identifier.getAncestor((node) => node is VariableDeclaration); | |
| 10177 expect(declaration.initializer.staticType.name, 'int'); | |
| 10178 expect(declaration.initializer.propagatedType, isNull); | |
| 10179 } | 10165 } |
| 10180 | 10166 |
| 10181 void test_MethodInvocation_nameType_localVariable() { | 10167 void test_MethodInvocation_nameType_localVariable() { |
| 10182 String code = r""" | 10168 String code = r""" |
| 10183 typedef Foo(); | 10169 typedef Foo(); |
| 10184 main() { | 10170 main() { |
| 10185 Foo foo; | 10171 Foo foo; |
| 10186 foo(); | 10172 foo(); |
| 10187 } | 10173 } |
| 10188 """; | 10174 """; |
| 10189 _resolveTestUnit(code); | 10175 _resolveTestUnit(code); |
| 10190 // "foo" should be resolved to the "Foo" type | 10176 // "foo" should be resolved to the "Foo" type |
| 10191 SimpleIdentifier identifier = _findIdentifier("foo();"); | 10177 _expectIdentifierType("foo();", new isInstanceOf<FunctionType>()); |
| 10192 DartType type = identifier.staticType; | |
| 10193 expect(type, new isInstanceOf<FunctionType>()); | |
| 10194 } | 10178 } |
| 10195 | 10179 |
| 10196 void test_MethodInvocation_nameType_parameter_FunctionTypeAlias() { | 10180 void test_MethodInvocation_nameType_parameter_FunctionTypeAlias() { |
| 10197 String code = r""" | 10181 String code = r""" |
| 10198 typedef Foo(); | 10182 typedef Foo(); |
| 10199 main(Foo foo) { | 10183 main(Foo foo) { |
| 10200 foo(); | 10184 foo(); |
| 10201 } | 10185 } |
| 10202 """; | 10186 """; |
| 10203 _resolveTestUnit(code); | 10187 _resolveTestUnit(code); |
| 10204 // "foo" should be resolved to the "Foo" type | 10188 // "foo" should be resolved to the "Foo" type |
| 10205 SimpleIdentifier identifier = _findIdentifier("foo();"); | 10189 _expectIdentifierType("foo();", new isInstanceOf<FunctionType>()); |
| 10206 DartType type = identifier.staticType; | |
| 10207 expect(type, new isInstanceOf<FunctionType>()); | |
| 10208 } | 10190 } |
| 10209 | 10191 |
| 10210 void test_MethodInvocation_nameType_parameter_propagatedType() { | 10192 void test_MethodInvocation_nameType_parameter_propagatedType() { |
| 10211 String code = r""" | 10193 String code = r""" |
| 10212 typedef Foo(); | 10194 typedef Foo(); |
| 10213 main(p) { | 10195 main(p) { |
| 10214 if (p is Foo) { | 10196 if (p is Foo) { |
| 10215 p(); | 10197 p(); |
| 10216 } | 10198 } |
| 10217 } | 10199 } |
| 10218 """; | 10200 """; |
| 10219 _resolveTestUnit(code); | 10201 _resolveTestUnit(code); |
| 10220 SimpleIdentifier identifier = _findIdentifier("p()"); | 10202 _expectIdentifierType("p()", DynamicTypeImpl.instance, |
| 10221 expect(identifier.staticType, DynamicTypeImpl.instance); | 10203 predicate((type) => type.name == 'Foo')); |
| 10222 { | |
| 10223 FunctionType type = identifier.propagatedType; | |
| 10224 expect(type, isNotNull); | |
| 10225 expect(type.name, 'Foo'); | |
| 10226 } | |
| 10227 } | 10204 } |
| 10228 | 10205 |
| 10229 void test_staticMethods_classTypeParameters() { | 10206 void test_staticMethods_classTypeParameters() { |
| 10230 String code = r''' | 10207 String code = r''' |
| 10231 class C<T> { | 10208 class C<T> { |
| 10232 static void m() => null; | 10209 static void m() => null; |
| 10233 } | 10210 } |
| 10234 main() { | 10211 main() { |
| 10235 print(C.m); | 10212 print(C.m); |
| 10236 } | 10213 } |
| 10237 '''; | 10214 '''; |
| 10238 _resolveTestUnit(code); | 10215 _resolveTestUnit(code); |
| 10239 SimpleIdentifier identifier = _findIdentifier('m);'); | 10216 _expectFunctionType('m);', '() → void'); |
| 10240 FunctionTypeImpl type = identifier.staticType; | |
| 10241 expect(type.toString(), '() → void'); | |
| 10242 expect(type.typeParameters, isEmpty, | |
| 10243 reason: 'static methods should not have type parameters'); | |
| 10244 expect(type.typeArguments, isEmpty, | |
| 10245 reason: 'static methods should not have type arguments'); | |
| 10246 expect(type.typeFormals, isEmpty, | |
| 10247 reason: 'this static method is not generic'); | |
| 10248 } | 10217 } |
| 10249 | 10218 |
| 10250 void test_staticMethods_classTypeParameters_genericMethod() { | 10219 void test_staticMethods_classTypeParameters_genericMethod() { |
| 10251 AnalysisOptionsImpl options = new AnalysisOptionsImpl(); | 10220 AnalysisOptionsImpl options = new AnalysisOptionsImpl(); |
| 10252 options.enableGenericMethods = true; | 10221 options.enableGenericMethods = true; |
| 10253 resetWithOptions(options); | 10222 resetWithOptions(options); |
| 10254 String code = r''' | 10223 String code = r''' |
| 10255 class C<T> { | 10224 class C<T> { |
| 10256 static void m<S>(S s) => null; | 10225 static void m<S>(S s) => null; |
| 10257 } | 10226 } |
| 10258 main() { | 10227 main() { |
| 10259 print(C.m); | 10228 print(C.m); |
| 10260 } | 10229 } |
| 10261 '''; | 10230 '''; |
| 10262 _resolveTestUnit(code); | 10231 _resolveTestUnit(code); |
| 10232 _expectFunctionType('m);', '<S>(S) → void', |
| 10233 elementTypeParams: '[S]', typeFormals: '[S]'); |
| 10234 |
| 10263 SimpleIdentifier identifier = _findIdentifier('m);'); | 10235 SimpleIdentifier identifier = _findIdentifier('m);'); |
| 10264 FunctionTypeImpl type = identifier.staticType; | 10236 FunctionTypeImpl type = identifier.staticType; |
| 10265 expect(type.toString(), '<S>(S) → void'); | |
| 10266 expect(type.typeParameters, isEmpty, | |
| 10267 reason: 'static methods should not have type parameters'); | |
| 10268 expect(type.typeArguments, isEmpty, | |
| 10269 reason: 'static methods should not have type arguments'); | |
| 10270 expect(type.typeFormals.toString(), '[S]'); | |
| 10271 | |
| 10272 type = type.instantiate([DynamicTypeImpl.instance]); | 10237 type = type.instantiate([DynamicTypeImpl.instance]); |
| 10273 expect(type.toString(), '(dynamic) → void'); | 10238 expect(type.toString(), '(dynamic) → void'); |
| 10274 expect(type.typeParameters.toString(), '[S]'); | 10239 expect(type.typeParameters.toString(), '[S]'); |
| 10275 expect(type.typeArguments, [DynamicTypeImpl.instance]); | 10240 expect(type.typeArguments, [DynamicTypeImpl.instance]); |
| 10276 expect(type.typeFormals, isEmpty); | 10241 expect(type.typeFormals, isEmpty); |
| 10277 } | 10242 } |
| 10278 } | 10243 } |
| 10279 | 10244 |
| 10280 @reflectiveTest | 10245 @reflectiveTest |
| 10281 class StaticTypeAnalyzerTest extends EngineTestCase { | 10246 class StaticTypeAnalyzerTest extends EngineTestCase { |
| (...skipping 3047 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 13329 /*=T*/ lf/*<T>*/(/*=T*/ e) => null; | 13294 /*=T*/ lf/*<T>*/(/*=T*/ e) => null; |
| 13330 var methodTearOffInst = c.f/*<int>*/; | 13295 var methodTearOffInst = c.f/*<int>*/; |
| 13331 var staticTearOffInst = C.g/*<int>*/; | 13296 var staticTearOffInst = C.g/*<int>*/; |
| 13332 var staticFieldTearOffInst = C.h/*<int>*/; | 13297 var staticFieldTearOffInst = C.h/*<int>*/; |
| 13333 var topFunTearOffInst = topF/*<int>*/; | 13298 var topFunTearOffInst = topF/*<int>*/; |
| 13334 var topFieldTearOffInst = topG/*<int>*/; | 13299 var topFieldTearOffInst = topG/*<int>*/; |
| 13335 var localTearOffInst = lf/*<int>*/; | 13300 var localTearOffInst = lf/*<int>*/; |
| 13336 var paramTearOffInst = pf/*<int>*/; | 13301 var paramTearOffInst = pf/*<int>*/; |
| 13337 } | 13302 } |
| 13338 '''); | 13303 '''); |
| 13339 expect(_findIdentifier('methodTearOffInst').staticType.toString(), | 13304 _expectIdentifierType('methodTearOffInst', "(int) → int"); |
| 13340 "(int) → int"); | 13305 _expectIdentifierType('staticTearOffInst', "(int) → int"); |
| 13341 expect(_findIdentifier('staticTearOffInst').staticType.toString(), | 13306 _expectIdentifierType('staticFieldTearOffInst', "(int) → int"); |
| 13342 "(int) → int"); | 13307 _expectIdentifierType('topFunTearOffInst', "(int) → int"); |
| 13343 expect(_findIdentifier('staticFieldTearOffInst').staticType.toString(), | 13308 _expectIdentifierType('topFieldTearOffInst', "(int) → int"); |
| 13344 "(int) → int"); | 13309 _expectIdentifierType('localTearOffInst', "(int) → int"); |
| 13345 expect(_findIdentifier('topFunTearOffInst').staticType.toString(), | 13310 _expectIdentifierType('paramTearOffInst', "(int) → int"); |
| 13346 "(int) → int"); | |
| 13347 expect(_findIdentifier('topFieldTearOffInst').staticType.toString(), | |
| 13348 "(int) → int"); | |
| 13349 expect(_findIdentifier('localTearOffInst').staticType.toString(), | |
| 13350 "(int) → int"); | |
| 13351 expect(_findIdentifier('paramTearOffInst').staticType.toString(), | |
| 13352 "(int) → int"); | |
| 13353 } | 13311 } |
| 13354 | 13312 |
| 13355 void setUp() { | 13313 void setUp() { |
| 13356 super.setUp(); | 13314 super.setUp(); |
| 13357 AnalysisOptionsImpl options = new AnalysisOptionsImpl(); | 13315 AnalysisOptionsImpl options = new AnalysisOptionsImpl(); |
| 13358 options.strongMode = true; | 13316 options.strongMode = true; |
| 13359 resetWithOptions(options); | 13317 resetWithOptions(options); |
| 13360 } | 13318 } |
| 13361 | 13319 |
| 13362 void test_dynamicObjectGetter_hashCode() { | 13320 void test_dynamicObjectGetter_hashCode() { |
| 13363 String code = r''' | 13321 String code = r''' |
| 13364 main() { | 13322 main() { |
| 13365 dynamic a = null; | 13323 dynamic a = null; |
| 13366 var foo = a.hashCode; | 13324 var foo = a.hashCode; |
| 13367 } | 13325 } |
| 13368 '''; | 13326 '''; |
| 13369 _resolveTestUnit(code); | 13327 _resolveTestUnit(code); |
| 13370 | 13328 _expectInitializerType('foo', 'int', isNull); |
| 13371 SimpleIdentifier identifier = _findIdentifier('foo'); | |
| 13372 VariableDeclaration declaration = | |
| 13373 identifier.getAncestor((node) => node is VariableDeclaration); | |
| 13374 expect(declaration.initializer.staticType.name, 'int'); | |
| 13375 expect(declaration.initializer.propagatedType, isNull); | |
| 13376 } | 13329 } |
| 13377 | 13330 |
| 13378 void test_dynamicObjectMethod_toString() { | 13331 void test_dynamicObjectMethod_toString() { |
| 13379 String code = r''' | 13332 String code = r''' |
| 13380 main() { | 13333 main() { |
| 13381 dynamic a = null; | 13334 dynamic a = null; |
| 13382 var foo = a.toString(); | 13335 var foo = a.toString(); |
| 13383 } | 13336 } |
| 13384 '''; | 13337 '''; |
| 13385 _resolveTestUnit(code); | 13338 _resolveTestUnit(code); |
| 13386 | 13339 _expectInitializerType('foo', 'String', isNull); |
| 13387 SimpleIdentifier identifier = _findIdentifier('foo'); | |
| 13388 VariableDeclaration declaration = | |
| 13389 identifier.getAncestor((node) => node is VariableDeclaration); | |
| 13390 expect(declaration.initializer.staticType.name, 'String'); | |
| 13391 expect(declaration.initializer.propagatedType, isNull); | |
| 13392 } | 13340 } |
| 13393 | 13341 |
| 13394 void test_genericFunction() { | 13342 void test_genericFunction() { |
| 13395 _resolveTestUnit(r'/*=T*/ f/*<T>*/(/*=T*/ x) => null;'); | 13343 _resolveTestUnit(r'/*=T*/ f/*<T>*/(/*=T*/ x) => null;'); |
| 13344 _expectFunctionType('f', '<T>(T) → T', |
| 13345 elementTypeParams: '[T]', typeFormals: '[T]'); |
| 13396 SimpleIdentifier f = _findIdentifier('f'); | 13346 SimpleIdentifier f = _findIdentifier('f'); |
| 13397 FunctionElementImpl e = f.staticElement; | 13347 FunctionElementImpl e = f.staticElement; |
| 13398 expect(e.typeParameters.toString(), '[T]'); | |
| 13399 expect(e.type.typeFormals.toString(), '[T]'); | |
| 13400 expect(e.type.typeParameters.toString(), '[]'); | |
| 13401 expect(e.type.toString(), '<T>(T) → T'); | |
| 13402 | |
| 13403 FunctionType ft = e.type.instantiate([typeProvider.stringType]); | 13348 FunctionType ft = e.type.instantiate([typeProvider.stringType]); |
| 13404 expect(ft.toString(), '(String) → String'); | 13349 expect(ft.toString(), '(String) → String'); |
| 13405 } | 13350 } |
| 13406 | 13351 |
| 13407 void test_genericFunction_bounds() { | 13352 void test_genericFunction_bounds() { |
| 13408 _resolveTestUnit(r'/*=T*/ f/*<T extends num>*/(/*=T*/ x) => null;'); | 13353 _resolveTestUnit(r'/*=T*/ f/*<T extends num>*/(/*=T*/ x) => null;'); |
| 13409 SimpleIdentifier f = _findIdentifier('f'); | 13354 _expectFunctionType('f', '<T extends num>(T) → T', |
| 13410 FunctionElementImpl e = f.staticElement; | 13355 elementTypeParams: '[T extends num]', typeFormals: '[T extends num]'); |
| 13411 expect(e.typeParameters.toString(), '[T extends num]'); | |
| 13412 expect(e.type.typeFormals.toString(), '[T extends num]'); | |
| 13413 expect(e.type.typeParameters.toString(), '[]'); | |
| 13414 expect(e.type.toString(), '<T extends num>(T) → T'); | |
| 13415 } | 13356 } |
| 13416 | 13357 |
| 13417 void test_genericFunction_parameter() { | 13358 void test_genericFunction_parameter() { |
| 13418 _resolveTestUnit(r''' | 13359 _resolveTestUnit(r''' |
| 13419 void g(/*=T*/ f/*<T>*/(/*=T*/ x)) {} | 13360 void g(/*=T*/ f/*<T>*/(/*=T*/ x)) {} |
| 13420 '''); | 13361 '''); |
| 13362 _expectFunctionType('f', '<T>(T) → T', |
| 13363 elementTypeParams: '[T]', typeFormals: '[T]'); |
| 13421 SimpleIdentifier f = _findIdentifier('f'); | 13364 SimpleIdentifier f = _findIdentifier('f'); |
| 13422 ParameterElementImpl e = f.staticElement; | 13365 ParameterElementImpl e = f.staticElement; |
| 13423 FunctionType type = e.type; | 13366 FunctionType type = e.type; |
| 13424 expect(e.typeParameters.toString(), '[T]'); | |
| 13425 expect(type.typeFormals.toString(), '[T]'); | |
| 13426 expect(type.toString(), '<T>(T) → T'); | |
| 13427 FunctionType ft = type.instantiate([typeProvider.stringType]); | 13367 FunctionType ft = type.instantiate([typeProvider.stringType]); |
| 13428 expect(ft.toString(), '(String) → String'); | 13368 expect(ft.toString(), '(String) → String'); |
| 13429 } | 13369 } |
| 13430 | 13370 |
| 13431 void test_genericFunction_static() { | 13371 void test_genericFunction_static() { |
| 13432 _resolveTestUnit(r''' | 13372 _resolveTestUnit(r''' |
| 13433 class C<E> { | 13373 class C<E> { |
| 13434 static /*=T*/ f/*<T>*/(/*=T*/ x) => null; | 13374 static /*=T*/ f/*<T>*/(/*=T*/ x) => null; |
| 13435 } | 13375 } |
| 13436 '''); | 13376 '''); |
| 13377 _expectFunctionType('f', '<T>(T) → T', |
| 13378 elementTypeParams: '[T]', typeFormals: '[T]'); |
| 13437 SimpleIdentifier f = _findIdentifier('f'); | 13379 SimpleIdentifier f = _findIdentifier('f'); |
| 13438 MethodElementImpl e = f.staticElement; | 13380 MethodElementImpl e = f.staticElement; |
| 13439 expect(e.typeParameters.toString(), '[T]'); | |
| 13440 expect(e.type.typeFormals.toString(), '[T]'); | |
| 13441 expect(e.type.typeParameters.toString(), '[]'); | |
| 13442 expect(e.type.typeArguments.toString(), '[]'); | |
| 13443 expect(e.type.toString(), '<T>(T) → T'); | |
| 13444 | |
| 13445 FunctionType ft = e.type.instantiate([typeProvider.stringType]); | 13381 FunctionType ft = e.type.instantiate([typeProvider.stringType]); |
| 13446 expect(ft.toString(), '(String) → String'); | 13382 expect(ft.toString(), '(String) → String'); |
| 13447 } | 13383 } |
| 13448 | 13384 |
| 13449 void test_genericFunction_typedef() { | 13385 void test_genericFunction_typedef() { |
| 13450 String code = r''' | 13386 String code = r''' |
| 13451 typedef T F<T>(T x); | 13387 typedef T F<T>(T x); |
| 13452 F f0; | 13388 F f0; |
| 13453 | 13389 |
| 13454 class C { | 13390 class C { |
| (...skipping 17 matching lines...) Expand all Loading... |
| 13472 f0(3); | 13408 f0(3); |
| 13473 f1(3); | 13409 f1(3); |
| 13474 f2(3); | 13410 f2(3); |
| 13475 f3(3); | 13411 f3(3); |
| 13476 f4(3); | 13412 f4(3); |
| 13477 } | 13413 } |
| 13478 } | 13414 } |
| 13479 '''; | 13415 '''; |
| 13480 _resolveTestUnit(code); | 13416 _resolveTestUnit(code); |
| 13481 | 13417 |
| 13482 { | 13418 checkBody(String className) { |
| 13483 List<Statement> statements = | 13419 List<Statement> statements = |
| 13484 AstFinder.getStatementsInMethod(testUnit, "C", "g"); | 13420 AstFinder.getStatementsInMethod(testUnit, className, "g"); |
| 13485 | 13421 |
| 13486 ExpressionStatement exps0 = statements[1]; | 13422 for (int i = 1; i <= 5; i++) { |
| 13487 ExpressionStatement exps1 = statements[2]; | 13423 Expression exp = (statements[i] as ExpressionStatement).expression; |
| 13488 ExpressionStatement exps2 = statements[3]; | 13424 expect(exp.staticType, typeProvider.dynamicType); |
| 13489 ExpressionStatement exps3 = statements[4]; | 13425 } |
| 13490 ExpressionStatement exps4 = statements[5]; | |
| 13491 Expression exp0 = exps0.expression; | |
| 13492 Expression exp1 = exps1.expression; | |
| 13493 Expression exp2 = exps2.expression; | |
| 13494 Expression exp3 = exps3.expression; | |
| 13495 Expression exp4 = exps4.expression; | |
| 13496 expect(exp0.staticType, typeProvider.dynamicType); | |
| 13497 expect(exp1.staticType, typeProvider.dynamicType); | |
| 13498 expect(exp2.staticType, typeProvider.dynamicType); | |
| 13499 expect(exp3.staticType, typeProvider.dynamicType); | |
| 13500 expect(exp4.staticType, typeProvider.dynamicType); | |
| 13501 } | 13426 } |
| 13502 { | |
| 13503 List<Statement> statements = | |
| 13504 AstFinder.getStatementsInMethod(testUnit, "D", "g"); | |
| 13505 | 13427 |
| 13506 ExpressionStatement exps0 = statements[1]; | 13428 checkBody("C"); |
| 13507 ExpressionStatement exps1 = statements[2]; | 13429 checkBody("D"); |
| 13508 ExpressionStatement exps2 = statements[3]; | |
| 13509 ExpressionStatement exps3 = statements[4]; | |
| 13510 ExpressionStatement exps4 = statements[5]; | |
| 13511 Expression exp0 = exps0.expression; | |
| 13512 Expression exp1 = exps1.expression; | |
| 13513 Expression exp2 = exps2.expression; | |
| 13514 Expression exp3 = exps3.expression; | |
| 13515 Expression exp4 = exps4.expression; | |
| 13516 expect(exp0.staticType, typeProvider.dynamicType); | |
| 13517 expect(exp1.staticType, typeProvider.dynamicType); | |
| 13518 expect(exp2.staticType, typeProvider.dynamicType); | |
| 13519 expect(exp3.staticType, typeProvider.dynamicType); | |
| 13520 expect(exp4.staticType, typeProvider.dynamicType); | |
| 13521 } | |
| 13522 } | 13430 } |
| 13523 | 13431 |
| 13524 void test_genericMethod() { | 13432 void test_genericMethod() { |
| 13525 _resolveTestUnit(r''' | 13433 _resolveTestUnit(r''' |
| 13526 class C<E> { | 13434 class C<E> { |
| 13527 List/*<T>*/ f/*<T>*/(E e) => null; | 13435 List/*<T>*/ f/*<T>*/(E e) => null; |
| 13528 } | 13436 } |
| 13529 main() { | 13437 main() { |
| 13530 C<String> cOfString; | 13438 C<String> cOfString; |
| 13531 } | 13439 } |
| 13532 '''); | 13440 '''); |
| 13533 SimpleIdentifier f = _findIdentifier('f'); | 13441 _expectFunctionType('f', '<T>(E) → List<T>', |
| 13534 MethodElementImpl e = f.staticElement; | 13442 elementTypeParams: '[T]', |
| 13535 expect(e.typeParameters.toString(), '[T]'); | 13443 typeParams: '[E]', |
| 13536 expect(e.type.typeFormals.toString(), '[T]'); | 13444 typeArgs: '[E]', |
| 13537 expect(e.type.typeParameters.toString(), '[E]'); | 13445 typeFormals: '[T]'); |
| 13538 expect(e.type.typeArguments.toString(), '[E]'); | |
| 13539 expect(e.type.toString(), '<T>(E) → List<T>'); | |
| 13540 | |
| 13541 SimpleIdentifier c = _findIdentifier('cOfString'); | 13446 SimpleIdentifier c = _findIdentifier('cOfString'); |
| 13542 FunctionType ft = (c.staticType as InterfaceType).getMethod('f').type; | 13447 FunctionType ft = (c.staticType as InterfaceType).getMethod('f').type; |
| 13543 expect(ft.toString(), '<T>(String) → List<T>'); | 13448 expect(ft.toString(), '<T>(String) → List<T>'); |
| 13544 ft = ft.instantiate([typeProvider.intType]); | 13449 ft = ft.instantiate([typeProvider.intType]); |
| 13545 expect(ft.toString(), '(String) → List<int>'); | 13450 expect(ft.toString(), '(String) → List<int>'); |
| 13546 expect('${ft.typeArguments}/${ft.typeParameters}', '[String, int]/[E, T]'); | 13451 expect('${ft.typeArguments}/${ft.typeParameters}', '[String, int]/[E, T]'); |
| 13547 } | 13452 } |
| 13548 | 13453 |
| 13549 void test_genericMethod_explicitTypeParams() { | 13454 void test_genericMethod_explicitTypeParams() { |
| 13550 _resolveTestUnit(r''' | 13455 _resolveTestUnit(r''' |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 13583 var lambdaCall = (/*<E>*/(/*=E*/ e) => e)/*<int>*/(3); | 13488 var lambdaCall = (/*<E>*/(/*=E*/ e) => e)/*<int>*/(3); |
| 13584 var methodCall = (c.f)/*<int>*/(3); | 13489 var methodCall = (c.f)/*<int>*/(3); |
| 13585 var staticCall = (C.g)/*<int>*/(3); | 13490 var staticCall = (C.g)/*<int>*/(3); |
| 13586 var staticFieldCall = (C.h)/*<int>*/(3); | 13491 var staticFieldCall = (C.h)/*<int>*/(3); |
| 13587 var topFunCall = (topF)/*<int>*/(3); | 13492 var topFunCall = (topF)/*<int>*/(3); |
| 13588 var topFieldCall = (topG)/*<int>*/(3); | 13493 var topFieldCall = (topG)/*<int>*/(3); |
| 13589 var localCall = (lf)/*<int>*/(3); | 13494 var localCall = (lf)/*<int>*/(3); |
| 13590 var paramCall = (pf)/*<int>*/(3); | 13495 var paramCall = (pf)/*<int>*/(3); |
| 13591 } | 13496 } |
| 13592 '''); | 13497 '''); |
| 13593 expect(_findIdentifier('methodCall').staticType.toString(), "int"); | 13498 _expectIdentifierType('methodCall', "int"); |
| 13594 expect(_findIdentifier('staticCall').staticType.toString(), "int"); | 13499 _expectIdentifierType('staticCall', "int"); |
| 13595 expect(_findIdentifier('staticFieldCall').staticType.toString(), "int"); | 13500 _expectIdentifierType('staticFieldCall', "int"); |
| 13596 expect(_findIdentifier('topFunCall').staticType.toString(), "int"); | 13501 _expectIdentifierType('topFunCall', "int"); |
| 13597 expect(_findIdentifier('topFieldCall').staticType.toString(), "int"); | 13502 _expectIdentifierType('topFieldCall', "int"); |
| 13598 expect(_findIdentifier('localCall').staticType.toString(), "int"); | 13503 _expectIdentifierType('localCall', "int"); |
| 13599 expect(_findIdentifier('paramCall').staticType.toString(), "int"); | 13504 _expectIdentifierType('paramCall', "int"); |
| 13600 expect(_findIdentifier('lambdaCall').staticType.toString(), "int"); | 13505 _expectIdentifierType('lambdaCall', "int"); |
| 13601 } | 13506 } |
| 13602 | 13507 |
| 13603 void test_genericMethod_functionExpressionInvocation_inferred() { | 13508 void test_genericMethod_functionExpressionInvocation_inferred() { |
| 13604 _resolveTestUnit(r''' | 13509 _resolveTestUnit(r''' |
| 13605 class C<E> { | 13510 class C<E> { |
| 13606 /*=T*/ f/*<T>*/(/*=T*/ e) => null; | 13511 /*=T*/ f/*<T>*/(/*=T*/ e) => null; |
| 13607 static /*=T*/ g/*<T>*/(/*=T*/ e) => null; | 13512 static /*=T*/ g/*<T>*/(/*=T*/ e) => null; |
| 13608 static final h = g; | 13513 static final h = g; |
| 13609 } | 13514 } |
| 13610 | 13515 |
| 13611 /*=T*/ topF/*<T>*/(/*=T*/ e) => null; | 13516 /*=T*/ topF/*<T>*/(/*=T*/ e) => null; |
| 13612 var topG = topF; | 13517 var topG = topF; |
| 13613 void test/*<S>*/(/*=T*/ pf/*<T>*/(/*=T*/ e)) { | 13518 void test/*<S>*/(/*=T*/ pf/*<T>*/(/*=T*/ e)) { |
| 13614 var c = new C<int>(); | 13519 var c = new C<int>(); |
| 13615 /*=T*/ lf/*<T>*/(/*=T*/ e) => null; | 13520 /*=T*/ lf/*<T>*/(/*=T*/ e) => null; |
| 13616 | 13521 |
| 13617 var lambdaCall = (/*<E>*/(/*=E*/ e) => e)(3); | 13522 var lambdaCall = (/*<E>*/(/*=E*/ e) => e)(3); |
| 13618 var methodCall = (c.f)(3); | 13523 var methodCall = (c.f)(3); |
| 13619 var staticCall = (C.g)(3); | 13524 var staticCall = (C.g)(3); |
| 13620 var staticFieldCall = (C.h)(3); | 13525 var staticFieldCall = (C.h)(3); |
| 13621 var topFunCall = (topF)(3); | 13526 var topFunCall = (topF)(3); |
| 13622 var topFieldCall = (topG)(3); | 13527 var topFieldCall = (topG)(3); |
| 13623 var localCall = (lf)(3); | 13528 var localCall = (lf)(3); |
| 13624 var paramCall = (pf)(3); | 13529 var paramCall = (pf)(3); |
| 13625 } | 13530 } |
| 13626 '''); | 13531 '''); |
| 13627 expect(_findIdentifier('methodCall').staticType.toString(), "int"); | 13532 _expectIdentifierType('methodCall', "int"); |
| 13628 expect(_findIdentifier('staticCall').staticType.toString(), "int"); | 13533 _expectIdentifierType('staticCall', "int"); |
| 13629 expect(_findIdentifier('staticFieldCall').staticType.toString(), "int"); | 13534 _expectIdentifierType('staticFieldCall', "int"); |
| 13630 expect(_findIdentifier('topFunCall').staticType.toString(), "int"); | 13535 _expectIdentifierType('topFunCall', "int"); |
| 13631 expect(_findIdentifier('topFieldCall').staticType.toString(), "int"); | 13536 _expectIdentifierType('topFieldCall', "int"); |
| 13632 expect(_findIdentifier('localCall').staticType.toString(), "int"); | 13537 _expectIdentifierType('localCall', "int"); |
| 13633 expect(_findIdentifier('paramCall').staticType.toString(), "int"); | 13538 _expectIdentifierType('paramCall', "int"); |
| 13634 expect(_findIdentifier('lambdaCall').staticType.toString(), "int"); | 13539 _expectIdentifierType('lambdaCall', "int"); |
| 13635 } | 13540 } |
| 13636 | 13541 |
| 13637 void test_genericMethod_functionInvocation_explicit() { | 13542 void test_genericMethod_functionInvocation_explicit() { |
| 13638 _resolveTestUnit(r''' | 13543 _resolveTestUnit(r''' |
| 13639 class C<E> { | 13544 class C<E> { |
| 13640 /*=T*/ f/*<T>*/(/*=T*/ e) => null; | 13545 /*=T*/ f/*<T>*/(/*=T*/ e) => null; |
| 13641 static /*=T*/ g/*<T>*/(/*=T*/ e) => null; | 13546 static /*=T*/ g/*<T>*/(/*=T*/ e) => null; |
| 13642 static final h = g; | 13547 static final h = g; |
| 13643 } | 13548 } |
| 13644 | 13549 |
| 13645 /*=T*/ topF/*<T>*/(/*=T*/ e) => null; | 13550 /*=T*/ topF/*<T>*/(/*=T*/ e) => null; |
| 13646 var topG = topF; | 13551 var topG = topF; |
| 13647 void test/*<S>*/(/*=T*/ pf/*<T>*/(/*=T*/ e)) { | 13552 void test/*<S>*/(/*=T*/ pf/*<T>*/(/*=T*/ e)) { |
| 13648 var c = new C<int>(); | 13553 var c = new C<int>(); |
| 13649 /*=T*/ lf/*<T>*/(/*=T*/ e) => null; | 13554 /*=T*/ lf/*<T>*/(/*=T*/ e) => null; |
| 13650 var methodCall = c.f/*<int>*/(3); | 13555 var methodCall = c.f/*<int>*/(3); |
| 13651 var staticCall = C.g/*<int>*/(3); | 13556 var staticCall = C.g/*<int>*/(3); |
| 13652 var staticFieldCall = C.h/*<int>*/(3); | 13557 var staticFieldCall = C.h/*<int>*/(3); |
| 13653 var topFunCall = topF/*<int>*/(3); | 13558 var topFunCall = topF/*<int>*/(3); |
| 13654 var topFieldCall = topG/*<int>*/(3); | 13559 var topFieldCall = topG/*<int>*/(3); |
| 13655 var localCall = lf/*<int>*/(3); | 13560 var localCall = lf/*<int>*/(3); |
| 13656 var paramCall = pf/*<int>*/(3); | 13561 var paramCall = pf/*<int>*/(3); |
| 13657 } | 13562 } |
| 13658 '''); | 13563 '''); |
| 13659 expect(_findIdentifier('methodCall').staticType.toString(), "int"); | 13564 _expectIdentifierType('methodCall', "int"); |
| 13660 expect(_findIdentifier('staticCall').staticType.toString(), "int"); | 13565 _expectIdentifierType('staticCall', "int"); |
| 13661 expect(_findIdentifier('staticFieldCall').staticType.toString(), "int"); | 13566 _expectIdentifierType('staticFieldCall', "int"); |
| 13662 expect(_findIdentifier('topFunCall').staticType.toString(), "int"); | 13567 _expectIdentifierType('topFunCall', "int"); |
| 13663 expect(_findIdentifier('topFieldCall').staticType.toString(), "int"); | 13568 _expectIdentifierType('topFieldCall', "int"); |
| 13664 expect(_findIdentifier('localCall').staticType.toString(), "int"); | 13569 _expectIdentifierType('localCall', "int"); |
| 13665 expect(_findIdentifier('paramCall').staticType.toString(), "int"); | 13570 _expectIdentifierType('paramCall', "int"); |
| 13666 } | 13571 } |
| 13667 | 13572 |
| 13668 void test_genericMethod_functionInvocation_inferred() { | 13573 void test_genericMethod_functionInvocation_inferred() { |
| 13669 _resolveTestUnit(r''' | 13574 _resolveTestUnit(r''' |
| 13670 class C<E> { | 13575 class C<E> { |
| 13671 /*=T*/ f/*<T>*/(/*=T*/ e) => null; | 13576 /*=T*/ f/*<T>*/(/*=T*/ e) => null; |
| 13672 static /*=T*/ g/*<T>*/(/*=T*/ e) => null; | 13577 static /*=T*/ g/*<T>*/(/*=T*/ e) => null; |
| 13673 static final h = g; | 13578 static final h = g; |
| 13674 } | 13579 } |
| 13675 | 13580 |
| 13676 /*=T*/ topF/*<T>*/(/*=T*/ e) => null; | 13581 /*=T*/ topF/*<T>*/(/*=T*/ e) => null; |
| 13677 var topG = topF; | 13582 var topG = topF; |
| 13678 void test/*<S>*/(/*=T*/ pf/*<T>*/(/*=T*/ e)) { | 13583 void test/*<S>*/(/*=T*/ pf/*<T>*/(/*=T*/ e)) { |
| 13679 var c = new C<int>(); | 13584 var c = new C<int>(); |
| 13680 /*=T*/ lf/*<T>*/(/*=T*/ e) => null; | 13585 /*=T*/ lf/*<T>*/(/*=T*/ e) => null; |
| 13681 var methodCall = c.f(3); | 13586 var methodCall = c.f(3); |
| 13682 var staticCall = C.g(3); | 13587 var staticCall = C.g(3); |
| 13683 var staticFieldCall = C.h(3); | 13588 var staticFieldCall = C.h(3); |
| 13684 var topFunCall = topF(3); | 13589 var topFunCall = topF(3); |
| 13685 var topFieldCall = topG(3); | 13590 var topFieldCall = topG(3); |
| 13686 var localCall = lf(3); | 13591 var localCall = lf(3); |
| 13687 var paramCall = pf(3); | 13592 var paramCall = pf(3); |
| 13688 } | 13593 } |
| 13689 '''); | 13594 '''); |
| 13690 expect(_findIdentifier('methodCall').staticType.toString(), "int"); | 13595 _expectIdentifierType('methodCall', "int"); |
| 13691 expect(_findIdentifier('staticCall').staticType.toString(), "int"); | 13596 _expectIdentifierType('staticCall', "int"); |
| 13692 expect(_findIdentifier('staticFieldCall').staticType.toString(), "int"); | 13597 _expectIdentifierType('staticFieldCall', "int"); |
| 13693 expect(_findIdentifier('topFunCall').staticType.toString(), "int"); | 13598 _expectIdentifierType('topFunCall', "int"); |
| 13694 expect(_findIdentifier('topFieldCall').staticType.toString(), "int"); | 13599 _expectIdentifierType('topFieldCall', "int"); |
| 13695 expect(_findIdentifier('localCall').staticType.toString(), "int"); | 13600 _expectIdentifierType('localCall', "int"); |
| 13696 expect(_findIdentifier('paramCall').staticType.toString(), "int"); | 13601 _expectIdentifierType('paramCall', "int"); |
| 13697 } | 13602 } |
| 13698 | 13603 |
| 13699 void test_genericMethod_functionTypedParameter() { | 13604 void test_genericMethod_functionTypedParameter() { |
| 13700 _resolveTestUnit(r''' | 13605 _resolveTestUnit(r''' |
| 13701 class C<E> { | 13606 class C<E> { |
| 13702 List/*<T>*/ f/*<T>*/(/*=T*/ f(E e)) => null; | 13607 List/*<T>*/ f/*<T>*/(/*=T*/ f(E e)) => null; |
| 13703 } | 13608 } |
| 13704 main() { | 13609 main() { |
| 13705 C<String> cOfString; | 13610 C<String> cOfString; |
| 13706 } | 13611 } |
| 13707 '''); | 13612 '''); |
| 13708 SimpleIdentifier f = _findIdentifier('f'); | 13613 _expectFunctionType('f', '<T>((E) → T) → List<T>', |
| 13709 MethodElementImpl e = f.staticElement; | 13614 elementTypeParams: '[T]', |
| 13710 expect(e.typeParameters.toString(), '[T]'); | 13615 typeParams: '[E]', |
| 13711 expect(e.type.typeFormals.toString(), '[T]'); | 13616 typeArgs: '[E]', |
| 13712 expect(e.type.typeParameters.toString(), '[E]'); | 13617 typeFormals: '[T]'); |
| 13713 expect(e.type.typeArguments.toString(), '[E]'); | |
| 13714 expect(e.type.toString(), '<T>((E) → T) → List<T>'); | |
| 13715 | 13618 |
| 13716 SimpleIdentifier c = _findIdentifier('cOfString'); | 13619 SimpleIdentifier c = _findIdentifier('cOfString'); |
| 13717 FunctionType ft = (c.staticType as InterfaceType).getMethod('f').type; | 13620 FunctionType ft = (c.staticType as InterfaceType).getMethod('f').type; |
| 13718 expect(ft.toString(), '<T>((String) → T) → List<T>'); | 13621 expect(ft.toString(), '<T>((String) → T) → List<T>'); |
| 13719 ft = ft.instantiate([typeProvider.intType]); | 13622 ft = ft.instantiate([typeProvider.intType]); |
| 13720 expect(ft.toString(), '((String) → int) → List<int>'); | 13623 expect(ft.toString(), '((String) → int) → List<int>'); |
| 13721 } | 13624 } |
| 13722 | 13625 |
| 13723 void test_genericMethod_implicitDynamic() { | 13626 void test_genericMethod_implicitDynamic() { |
| 13724 // Regression test for: | 13627 // Regression test for: |
| 13725 // https://github.com/dart-lang/sdk/issues/25100#issuecomment-162047588 | 13628 // https://github.com/dart-lang/sdk/issues/25100#issuecomment-162047588 |
| 13726 // These should not cause any hints or warnings. | 13629 // These should not cause any hints or warnings. |
| 13727 _resolveTestUnit(r''' | 13630 _resolveTestUnit(r''' |
| 13728 class List<E> { | 13631 class List<E> { |
| 13729 /*=T*/ map/*<T>*/(/*=T*/ f(E e)) => null; | 13632 /*=T*/ map/*<T>*/(/*=T*/ f(E e)) => null; |
| 13730 } | 13633 } |
| 13731 void foo() { | 13634 void foo() { |
| 13732 List list = null; | 13635 List list = null; |
| 13733 list.map((e) => e); | 13636 list.map((e) => e); |
| 13734 list.map((e) => 3); | 13637 list.map((e) => 3); |
| 13735 }'''); | 13638 }'''); |
| 13639 _expectIdentifierType('map((e) => e);', '<T>((dynamic) → T) → T', isNull); |
| 13640 _expectIdentifierType('map((e) => 3);', '<T>((dynamic) → T) → T', isNull); |
| 13736 | 13641 |
| 13737 SimpleIdentifier map1 = _findIdentifier('map((e) => e);'); | 13642 MethodInvocation m1 = _findIdentifier('map((e) => e);').parent; |
| 13738 MethodInvocation m1 = map1.parent; | |
| 13739 expect(m1.staticInvokeType.toString(), '((dynamic) → dynamic) → dynamic'); | 13643 expect(m1.staticInvokeType.toString(), '((dynamic) → dynamic) → dynamic'); |
| 13740 expect(map1.staticType.toString(), '<T>((dynamic) → T) → T'); | 13644 MethodInvocation m2 = _findIdentifier('map((e) => 3);').parent; |
| 13741 expect(map1.propagatedType, isNull); | |
| 13742 SimpleIdentifier map2 = _findIdentifier('map((e) => 3);'); | |
| 13743 MethodInvocation m2 = map2.parent; | |
| 13744 expect(m2.staticInvokeType.toString(), '((dynamic) → int) → int'); | 13645 expect(m2.staticInvokeType.toString(), '((dynamic) → int) → int'); |
| 13745 expect(map2.staticType.toString(), '<T>((dynamic) → T) → T'); | |
| 13746 expect(map2.propagatedType, isNull); | |
| 13747 } | 13646 } |
| 13748 | 13647 |
| 13749 void test_genericMethod_max_doubleDouble() { | 13648 void test_genericMethod_max_doubleDouble() { |
| 13750 String code = r''' | 13649 String code = r''' |
| 13751 import 'dart:math'; | 13650 import 'dart:math'; |
| 13752 main() { | 13651 main() { |
| 13753 var foo = max(1.0, 2.0); | 13652 var foo = max(1.0, 2.0); |
| 13754 } | 13653 } |
| 13755 '''; | 13654 '''; |
| 13756 _resolveTestUnit(code); | 13655 _resolveTestUnit(code); |
| 13757 | 13656 _expectInitializerType('foo', 'double', isNull); |
| 13758 SimpleIdentifier identifier = _findIdentifier('foo'); | |
| 13759 VariableDeclaration declaration = | |
| 13760 identifier.getAncestor((node) => node is VariableDeclaration); | |
| 13761 expect(declaration.initializer.staticType.name, 'double'); | |
| 13762 expect(declaration.initializer.propagatedType, isNull); | |
| 13763 } | 13657 } |
| 13764 | 13658 |
| 13765 void test_genericMethod_max_doubleDouble_prefixed() { | 13659 void test_genericMethod_max_doubleDouble_prefixed() { |
| 13766 String code = r''' | 13660 String code = r''' |
| 13767 import 'dart:math' as math; | 13661 import 'dart:math' as math; |
| 13768 main() { | 13662 main() { |
| 13769 var foo = math.max(1.0, 2.0); | 13663 var foo = math.max(1.0, 2.0); |
| 13770 } | 13664 } |
| 13771 '''; | 13665 '''; |
| 13772 _resolveTestUnit(code); | 13666 _resolveTestUnit(code); |
| 13773 | 13667 _expectInitializerType('foo', 'double', isNull); |
| 13774 SimpleIdentifier identifier = _findIdentifier('foo'); | |
| 13775 VariableDeclaration declaration = | |
| 13776 identifier.getAncestor((node) => node is VariableDeclaration); | |
| 13777 expect(declaration.initializer.staticType.name, 'double'); | |
| 13778 expect(declaration.initializer.propagatedType, isNull); | |
| 13779 } | 13668 } |
| 13780 | 13669 |
| 13781 void test_genericMethod_max_doubleInt() { | 13670 void test_genericMethod_max_doubleInt() { |
| 13782 String code = r''' | 13671 String code = r''' |
| 13783 import 'dart:math'; | 13672 import 'dart:math'; |
| 13784 main() { | 13673 main() { |
| 13785 var foo = max(1.0, 2); | 13674 var foo = max(1.0, 2); |
| 13786 } | 13675 } |
| 13787 '''; | 13676 '''; |
| 13788 _resolveTestUnit(code); | 13677 _resolveTestUnit(code); |
| 13789 | 13678 _expectInitializerType('foo', 'num', isNull); |
| 13790 SimpleIdentifier identifier = _findIdentifier('foo'); | |
| 13791 VariableDeclaration declaration = | |
| 13792 identifier.getAncestor((node) => node is VariableDeclaration); | |
| 13793 expect(declaration.initializer.staticType.name, 'num'); | |
| 13794 expect(declaration.initializer.propagatedType, isNull); | |
| 13795 } | 13679 } |
| 13796 | 13680 |
| 13797 void test_genericMethod_max_intDouble() { | 13681 void test_genericMethod_max_intDouble() { |
| 13798 String code = r''' | 13682 String code = r''' |
| 13799 import 'dart:math'; | 13683 import 'dart:math'; |
| 13800 main() { | 13684 main() { |
| 13801 var foo = max(1, 2.0); | 13685 var foo = max(1, 2.0); |
| 13802 } | 13686 } |
| 13803 '''; | 13687 '''; |
| 13804 _resolveTestUnit(code); | 13688 _resolveTestUnit(code); |
| 13805 | 13689 _expectInitializerType('foo', 'num', isNull); |
| 13806 SimpleIdentifier identifier = _findIdentifier('foo'); | |
| 13807 VariableDeclaration declaration = | |
| 13808 identifier.getAncestor((node) => node is VariableDeclaration); | |
| 13809 expect(declaration.initializer.staticType.name, 'num'); | |
| 13810 expect(declaration.initializer.propagatedType, isNull); | |
| 13811 } | 13690 } |
| 13812 | 13691 |
| 13813 void test_genericMethod_max_intInt() { | 13692 void test_genericMethod_max_intInt() { |
| 13814 String code = r''' | 13693 String code = r''' |
| 13815 import 'dart:math'; | 13694 import 'dart:math'; |
| 13816 main() { | 13695 main() { |
| 13817 var foo = max(1, 2); | 13696 var foo = max(1, 2); |
| 13818 } | 13697 } |
| 13819 '''; | 13698 '''; |
| 13820 _resolveTestUnit(code); | 13699 _resolveTestUnit(code); |
| 13821 | 13700 _expectInitializerType('foo', 'int', isNull); |
| 13822 SimpleIdentifier identifier = _findIdentifier('foo'); | |
| 13823 VariableDeclaration declaration = | |
| 13824 identifier.getAncestor((node) => node is VariableDeclaration); | |
| 13825 expect(declaration.initializer.staticType.name, 'int'); | |
| 13826 expect(declaration.initializer.propagatedType, isNull); | |
| 13827 } | 13701 } |
| 13828 | 13702 |
| 13829 void test_genericMethod_nestedBound() { | 13703 void test_genericMethod_nestedBound() { |
| 13830 String code = r''' | 13704 String code = r''' |
| 13831 class Foo<T extends num> { | 13705 class Foo<T extends num> { |
| 13832 void method/*<U extends T>*/(dynamic/*=U*/ u) { | 13706 void method/*<U extends T>*/(dynamic/*=U*/ u) { |
| 13833 u.abs(); | 13707 u.abs(); |
| 13834 } | 13708 } |
| 13835 } | 13709 } |
| 13836 '''; | 13710 '''; |
| 13837 // Just validate that there is no warning on the call to `.abs()`. | 13711 // Just validate that there is no warning on the call to `.abs()`. |
| 13838 _resolveTestUnit(code); | 13712 _resolveTestUnit(code); |
| 13839 } | 13713 } |
| 13840 | 13714 |
| 13841 void test_genericMethod_nestedCapture() { | 13715 void test_genericMethod_nestedCapture() { |
| 13842 _resolveTestUnit(r''' | 13716 _resolveTestUnit(r''' |
| 13843 class C<T> { | 13717 class C<T> { |
| 13844 /*=T*/ f/*<S>*/(/*=S*/ x) { | 13718 /*=T*/ f/*<S>*/(/*=S*/ x) { |
| 13845 new C<S>().f/*<int>*/(3); | 13719 new C<S>().f/*<int>*/(3); |
| 13846 new C<S>().f; // tear-off | 13720 new C<S>().f; // tear-off |
| 13847 return null; | 13721 return null; |
| 13848 } | 13722 } |
| 13849 } | 13723 } |
| 13850 '''); | 13724 '''); |
| 13851 MethodInvocation f = _findIdentifier('f/*<int>*/(3);').parent; | 13725 MethodInvocation f = _findIdentifier('f/*<int>*/(3);').parent; |
| 13852 expect(f.staticInvokeType.toString(), '(int) → S'); | 13726 expect(f.staticInvokeType.toString(), '(int) → S'); |
| 13853 FunctionType ft = f.staticInvokeType; | 13727 FunctionType ft = f.staticInvokeType; |
| 13854 expect('${ft.typeArguments}/${ft.typeParameters}', '[S, int]/[T, S]'); | 13728 expect('${ft.typeArguments}/${ft.typeParameters}', '[S, int]/[T, S]'); |
| 13855 | 13729 |
| 13856 SimpleIdentifier f2 = _findIdentifier('f;'); | 13730 _expectIdentifierType('f;', '<S₀>(S₀) → S'); |
| 13857 expect(f2.staticType.toString(), '<S₀>(S₀) → S'); | |
| 13858 } | 13731 } |
| 13859 | 13732 |
| 13860 void test_genericMethod_nestedFunctions() { | 13733 void test_genericMethod_nestedFunctions() { |
| 13861 _resolveTestUnit(r''' | 13734 _resolveTestUnit(r''' |
| 13862 /*=S*/ f/*<S>*/(/*=S*/ x) { | 13735 /*=S*/ f/*<S>*/(/*=S*/ x) { |
| 13863 g/*<S>*/(/*=S*/ x) => f; | 13736 g/*<S>*/(/*=S*/ x) => f; |
| 13864 return null; | 13737 return null; |
| 13865 } | 13738 } |
| 13866 '''); | 13739 '''); |
| 13867 SimpleIdentifier g = _findIdentifier('f'); | 13740 _expectIdentifierType('f', '<S>(S) → S'); |
| 13868 expect(g.staticType.toString(), '<S>(S) → S'); | 13741 _expectIdentifierType('g', '<S>(S) → dynamic'); |
| 13869 SimpleIdentifier f = _findIdentifier('g'); | |
| 13870 expect(f.staticType.toString(), '<S>(S) → dynamic'); | |
| 13871 } | 13742 } |
| 13872 | 13743 |
| 13873 void test_genericMethod_override() { | 13744 void test_genericMethod_override() { |
| 13874 _resolveTestUnit(r''' | 13745 _resolveTestUnit(r''' |
| 13875 class C { | 13746 class C { |
| 13876 /*=T*/ f/*<T>*/(/*=T*/ x) => null; | 13747 /*=T*/ f/*<T>*/(/*=T*/ x) => null; |
| 13877 } | 13748 } |
| 13878 class D extends C { | 13749 class D extends C { |
| 13879 /*=T*/ f/*<T>*/(/*=T*/ x) => null; // from D | 13750 /*=T*/ f/*<T>*/(/*=T*/ x) => null; // from D |
| 13880 } | 13751 } |
| 13881 '''); | 13752 '''); |
| 13753 _expectFunctionType('f/*<T>*/(/*=T*/ x) => null; // from D', '<T>(T) → T', |
| 13754 elementTypeParams: '[T]', typeFormals: '[T]'); |
| 13882 SimpleIdentifier f = | 13755 SimpleIdentifier f = |
| 13883 _findIdentifier('f/*<T>*/(/*=T*/ x) => null; // from D'); | 13756 _findIdentifier('f/*<T>*/(/*=T*/ x) => null; // from D'); |
| 13884 MethodElementImpl e = f.staticElement; | 13757 MethodElementImpl e = f.staticElement; |
| 13885 expect(e.typeParameters.toString(), '[T]'); | |
| 13886 expect(e.type.typeFormals.toString(), '[T]'); | |
| 13887 expect(e.type.toString(), '<T>(T) → T'); | |
| 13888 | |
| 13889 FunctionType ft = e.type.instantiate([typeProvider.stringType]); | 13758 FunctionType ft = e.type.instantiate([typeProvider.stringType]); |
| 13890 expect(ft.toString(), '(String) → String'); | 13759 expect(ft.toString(), '(String) → String'); |
| 13891 } | 13760 } |
| 13892 | 13761 |
| 13893 void test_genericMethod_override_bounds() { | 13762 void test_genericMethod_override_bounds() { |
| 13894 _resolveTestUnit(r''' | 13763 _resolveTestUnit(r''' |
| 13895 class A {} | 13764 class A {} |
| 13896 class B extends A {} | 13765 class B extends A {} |
| 13897 class C { | 13766 class C { |
| 13898 /*=T*/ f/*<T extends B>*/(/*=T*/ x) => null; | 13767 /*=T*/ f/*<T extends B>*/(/*=T*/ x) => null; |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 13975 abstract class Iter { | 13844 abstract class Iter { |
| 13976 List/*<S>*/ map/*<S>*/(/*=S*/ f(x)); | 13845 List/*<S>*/ map/*<S>*/(/*=S*/ f(x)); |
| 13977 } | 13846 } |
| 13978 class C {} | 13847 class C {} |
| 13979 C toSpan(dynamic element) { | 13848 C toSpan(dynamic element) { |
| 13980 if (element is Iter) { | 13849 if (element is Iter) { |
| 13981 var y = element.map(toSpan); | 13850 var y = element.map(toSpan); |
| 13982 } | 13851 } |
| 13983 return null; | 13852 return null; |
| 13984 }'''); | 13853 }'''); |
| 13985 SimpleIdentifier y = _findIdentifier('y = '); | 13854 _expectIdentifierType('y = ', 'List<C>', isNull); |
| 13986 expect(y.staticType.toString(), 'List<C>'); | |
| 13987 expect(y.propagatedType, isNull); | |
| 13988 } | 13855 } |
| 13989 | 13856 |
| 13990 void test_genericMethod_tearoff() { | 13857 void test_genericMethod_tearoff() { |
| 13991 _resolveTestUnit(r''' | 13858 _resolveTestUnit(r''' |
| 13992 class C<E> { | 13859 class C<E> { |
| 13993 /*=T*/ f/*<T>*/(E e) => null; | 13860 /*=T*/ f/*<T>*/(E e) => null; |
| 13994 static /*=T*/ g/*<T>*/(/*=T*/ e) => null; | 13861 static /*=T*/ g/*<T>*/(/*=T*/ e) => null; |
| 13995 static final h = g; | 13862 static final h = g; |
| 13996 } | 13863 } |
| 13997 | 13864 |
| 13998 /*=T*/ topF/*<T>*/(/*=T*/ e) => null; | 13865 /*=T*/ topF/*<T>*/(/*=T*/ e) => null; |
| 13999 var topG = topF; | 13866 var topG = topF; |
| 14000 void test/*<S>*/(/*=T*/ pf/*<T>*/(/*=T*/ e)) { | 13867 void test/*<S>*/(/*=T*/ pf/*<T>*/(/*=T*/ e)) { |
| 14001 var c = new C<int>(); | 13868 var c = new C<int>(); |
| 14002 /*=T*/ lf/*<T>*/(/*=T*/ e) => null; | 13869 /*=T*/ lf/*<T>*/(/*=T*/ e) => null; |
| 14003 var methodTearOff = c.f; | 13870 var methodTearOff = c.f; |
| 14004 var staticTearOff = C.g; | 13871 var staticTearOff = C.g; |
| 14005 var staticFieldTearOff = C.h; | 13872 var staticFieldTearOff = C.h; |
| 14006 var topFunTearOff = topF; | 13873 var topFunTearOff = topF; |
| 14007 var topFieldTearOff = topG; | 13874 var topFieldTearOff = topG; |
| 14008 var localTearOff = lf; | 13875 var localTearOff = lf; |
| 14009 var paramTearOff = pf; | 13876 var paramTearOff = pf; |
| 14010 } | 13877 } |
| 14011 '''); | 13878 '''); |
| 14012 expect( | 13879 _expectIdentifierType('methodTearOff', "<T>(int) → T"); |
| 14013 _findIdentifier('methodTearOff').staticType.toString(), "<T>(int) → T"); | 13880 _expectIdentifierType('staticTearOff', "<T>(T) → T"); |
| 14014 expect( | 13881 _expectIdentifierType('staticFieldTearOff', "<T>(T) → T"); |
| 14015 _findIdentifier('staticTearOff').staticType.toString(), "<T>(T) → T"); | 13882 _expectIdentifierType('topFunTearOff', "<T>(T) → T"); |
| 14016 expect(_findIdentifier('staticFieldTearOff').staticType.toString(), | 13883 _expectIdentifierType('topFieldTearOff', "<T>(T) → T"); |
| 14017 "<T>(T) → T"); | 13884 _expectIdentifierType('localTearOff', "<T>(T) → T"); |
| 14018 expect( | 13885 _expectIdentifierType('paramTearOff', "<T>(T) → T"); |
| 14019 _findIdentifier('topFunTearOff').staticType.toString(), "<T>(T) → T"); | |
| 14020 expect( | |
| 14021 _findIdentifier('topFieldTearOff').staticType.toString(), "<T>(T) → T"); | |
| 14022 expect(_findIdentifier('localTearOff').staticType.toString(), "<T>(T) → T"); | |
| 14023 expect(_findIdentifier('paramTearOff').staticType.toString(), "<T>(T) → T"); | |
| 14024 } | 13886 } |
| 14025 | 13887 |
| 14026 void test_genericMethod_then() { | 13888 void test_genericMethod_then() { |
| 14027 String code = r''' | 13889 String code = r''' |
| 14028 import 'dart:async'; | 13890 import 'dart:async'; |
| 14029 String toString(int x) => x.toString(); | 13891 String toString(int x) => x.toString(); |
| 14030 main() { | 13892 main() { |
| 14031 Future<int> bar = null; | 13893 Future<int> bar = null; |
| 14032 var foo = bar.then(toString); | 13894 var foo = bar.then(toString); |
| 14033 } | 13895 } |
| 14034 '''; | 13896 '''; |
| 14035 _resolveTestUnit(code); | 13897 _resolveTestUnit(code); |
| 14036 | 13898 _expectInitializerType('foo', 'Future<String>', isNull); |
| 14037 SimpleIdentifier identifier = _findIdentifier('foo'); | |
| 14038 VariableDeclaration declaration = | |
| 14039 identifier.getAncestor((node) => node is VariableDeclaration); | |
| 14040 | |
| 14041 expect(declaration.initializer.staticType.toString(), "Future<String>"); | |
| 14042 expect(declaration.initializer.propagatedType, isNull); | |
| 14043 } | 13899 } |
| 14044 | 13900 |
| 14045 void test_genericMethod_then_prefixed() { | 13901 void test_genericMethod_then_prefixed() { |
| 14046 String code = r''' | 13902 String code = r''' |
| 14047 import 'dart:async' as async; | 13903 import 'dart:async' as async; |
| 14048 String toString(int x) => x.toString(); | 13904 String toString(int x) => x.toString(); |
| 14049 main() { | 13905 main() { |
| 14050 async.Future<int> bar = null; | 13906 async.Future<int> bar = null; |
| 14051 var foo = bar.then(toString); | 13907 var foo = bar.then(toString); |
| 14052 } | 13908 } |
| 14053 '''; | 13909 '''; |
| 14054 _resolveTestUnit(code); | 13910 _resolveTestUnit(code); |
| 14055 | 13911 _expectInitializerType('foo', 'Future<String>', isNull); |
| 14056 SimpleIdentifier identifier = _findIdentifier('foo'); | |
| 14057 VariableDeclaration declaration = | |
| 14058 identifier.getAncestor((node) => node is VariableDeclaration); | |
| 14059 | |
| 14060 expect(declaration.initializer.staticType.toString(), "Future<String>"); | |
| 14061 expect(declaration.initializer.propagatedType, isNull); | |
| 14062 } | 13912 } |
| 14063 | 13913 |
| 14064 void test_genericMethod_then_propagatedType() { | 13914 void test_genericMethod_then_propagatedType() { |
| 14065 // Regression test for https://github.com/dart-lang/sdk/issues/25482. | 13915 // Regression test for https://github.com/dart-lang/sdk/issues/25482. |
| 14066 String code = r''' | 13916 String code = r''' |
| 14067 import 'dart:async'; | 13917 import 'dart:async'; |
| 14068 void main() { | 13918 void main() { |
| 14069 Future<String> p; | 13919 Future<String> p; |
| 14070 var foo = p.then((r) => new Future<String>.value(3)); | 13920 var foo = p.then((r) => new Future<String>.value(3)); |
| 14071 } | 13921 } |
| 14072 '''; | 13922 '''; |
| 14073 // This should produce no hints or warnings. | 13923 // This should produce no hints or warnings. |
| 14074 _resolveTestUnit(code); | 13924 _resolveTestUnit(code); |
| 14075 VariableDeclaration foo = _findIdentifier('foo').parent; | 13925 _expectInitializerType('foo', 'Future<String>', isNull); |
| 14076 expect(foo.initializer.staticType.toString(), "Future<String>"); | |
| 14077 expect(foo.initializer.propagatedType, isNull); | |
| 14078 } | 13926 } |
| 14079 | 13927 |
| 14080 void test_setterWithDynamicTypeIsError() { | 13928 void test_setterWithDynamicTypeIsError() { |
| 14081 Source source = addSource(r''' | 13929 Source source = addSource(r''' |
| 14082 class A { | 13930 class A { |
| 14083 dynamic set f(String s) => null; | 13931 dynamic set f(String s) => null; |
| 14084 } | 13932 } |
| 14085 dynamic set g(int x) => null; | 13933 dynamic set g(int x) => null; |
| 14086 '''); | 13934 '''); |
| 14087 computeLibrarySourceErrors(source); | 13935 computeLibrarySourceErrors(source); |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 14150 verify([source]); | 13998 verify([source]); |
| 14151 } | 13999 } |
| 14152 | 14000 |
| 14153 void test_ternaryOperator_null_left() { | 14001 void test_ternaryOperator_null_left() { |
| 14154 String code = r''' | 14002 String code = r''' |
| 14155 main() { | 14003 main() { |
| 14156 var foo = (true) ? null : 3; | 14004 var foo = (true) ? null : 3; |
| 14157 } | 14005 } |
| 14158 '''; | 14006 '''; |
| 14159 _resolveTestUnit(code); | 14007 _resolveTestUnit(code); |
| 14160 | 14008 _expectInitializerType('foo', 'int', isNull); |
| 14161 SimpleIdentifier identifier = _findIdentifier('foo'); | |
| 14162 VariableDeclaration declaration = | |
| 14163 identifier.getAncestor((node) => node is VariableDeclaration); | |
| 14164 expect(declaration.initializer.staticType.name, 'int'); | |
| 14165 expect(declaration.initializer.propagatedType, isNull); | |
| 14166 } | 14009 } |
| 14167 | 14010 |
| 14168 void test_ternaryOperator_null_right() { | 14011 void test_ternaryOperator_null_right() { |
| 14169 String code = r''' | 14012 String code = r''' |
| 14170 main() { | 14013 main() { |
| 14171 var foo = (true) ? 3 : null; | 14014 var foo = (true) ? 3 : null; |
| 14172 } | 14015 } |
| 14173 '''; | 14016 '''; |
| 14174 _resolveTestUnit(code); | 14017 _resolveTestUnit(code); |
| 14175 | 14018 _expectInitializerType('foo', 'int', isNull); |
| 14176 SimpleIdentifier identifier = _findIdentifier('foo'); | |
| 14177 VariableDeclaration declaration = | |
| 14178 identifier.getAncestor((node) => node is VariableDeclaration); | |
| 14179 expect(declaration.initializer.staticType.name, 'int'); | |
| 14180 expect(declaration.initializer.propagatedType, isNull); | |
| 14181 } | 14019 } |
| 14182 } | 14020 } |
| 14183 | 14021 |
| 14184 @reflectiveTest | 14022 @reflectiveTest |
| 14185 class StrongModeTypePropagationTest extends ResolverTestCase { | 14023 class StrongModeTypePropagationTest extends ResolverTestCase { |
| 14186 @override | 14024 @override |
| 14187 void setUp() { | 14025 void setUp() { |
| 14188 super.setUp(); | 14026 super.setUp(); |
| 14189 AnalysisOptionsImpl options = new AnalysisOptionsImpl(); | 14027 AnalysisOptionsImpl options = new AnalysisOptionsImpl(); |
| 14190 options.strongMode = true; | 14028 options.strongMode = true; |
| (...skipping 2895 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 17086 String testCode; | 16924 String testCode; |
| 17087 Source testSource; | 16925 Source testSource; |
| 17088 CompilationUnit testUnit; | 16926 CompilationUnit testUnit; |
| 17089 | 16927 |
| 17090 SimpleIdentifier _findIdentifier(String search) { | 16928 SimpleIdentifier _findIdentifier(String search) { |
| 17091 SimpleIdentifier identifier = EngineTestCase.findNode( | 16929 SimpleIdentifier identifier = EngineTestCase.findNode( |
| 17092 testUnit, testCode, search, (node) => node is SimpleIdentifier); | 16930 testUnit, testCode, search, (node) => node is SimpleIdentifier); |
| 17093 return identifier; | 16931 return identifier; |
| 17094 } | 16932 } |
| 17095 | 16933 |
| 16934 /** |
| 16935 * Looks up the identifier with [name] and validates its static [type]. |
| 16936 * |
| 16937 * If [type] is a string, validates that the identifier's static type |
| 16938 * stringifies to that text. Otherwise, [type] is used directly a [Matcher] |
| 16939 * to match the type. |
| 16940 * |
| 16941 * If [propagatedType] is given, also validate's the identifier's propagated |
| 16942 * type. |
| 16943 */ |
| 16944 void _expectIdentifierType(String name, type, [propagatedType]) { |
| 16945 SimpleIdentifier identifier = _findIdentifier(name); |
| 16946 _expectType(identifier.staticType, type); |
| 16947 if (propagatedType != null) { |
| 16948 _expectType(identifier.propagatedType, propagatedType); |
| 16949 } |
| 16950 } |
| 16951 |
| 16952 /** |
| 16953 * Looks up the initializer for the declaration containing [identifier] and |
| 16954 * validates its static [type]. |
| 16955 * |
| 16956 * If [type] is a string, validates that the identifier's static type |
| 16957 * stringifies to that text. Otherwise, [type] is used directly a [Matcher] |
| 16958 * to match the type. |
| 16959 * |
| 16960 * If [propagatedType] is given, also validate's the identifier's propagated |
| 16961 * type. |
| 16962 */ |
| 16963 void _expectInitializerType(String name, type, [propagatedType]) { |
| 16964 SimpleIdentifier identifier = _findIdentifier(name); |
| 16965 VariableDeclaration declaration = |
| 16966 identifier.getAncestor((node) => node is VariableDeclaration); |
| 16967 Expression initializer = declaration.initializer; |
| 16968 _expectType(initializer.staticType, type); |
| 16969 if (propagatedType != null) { |
| 16970 _expectType(initializer.propagatedType, propagatedType); |
| 16971 } |
| 16972 } |
| 16973 |
| 16974 /** |
| 16975 * Looks up the identifier with [name] and validates that its type type |
| 16976 * stringifies to [type] and that its generics match the given stringified |
| 16977 * output. |
| 16978 */ |
| 16979 _expectFunctionType(String name, String type, |
| 16980 {String elementTypeParams: '[]', |
| 16981 String typeParams: '[]', |
| 16982 String typeArgs: '[]', |
| 16983 String typeFormals: '[]'}) { |
| 16984 SimpleIdentifier identifier = _findIdentifier(name); |
| 16985 // Element is either ExecutableElement or ParameterElement. |
| 16986 var element = identifier.staticElement; |
| 16987 FunctionTypeImpl functionType = identifier.staticType; |
| 16988 expect(functionType.toString(), type); |
| 16989 expect(element.typeParameters.toString(), elementTypeParams); |
| 16990 expect(functionType.typeParameters.toString(), typeParams); |
| 16991 expect(functionType.typeArguments.toString(), typeArgs); |
| 16992 expect(functionType.typeFormals.toString(), typeFormals); |
| 16993 } |
| 16994 |
| 16995 /** |
| 16996 * Validates that [type] matches [expected]. |
| 16997 * |
| 16998 * If [expected] is a string, validates that the type stringifies to that |
| 16999 * text. Otherwise, [expected] is used directly a [Matcher] to match the type. |
| 17000 */ |
| 17001 _expectType(DartType type, expected) { |
| 17002 if (expected is String) { |
| 17003 expect(type.toString(), expected); |
| 17004 } else { |
| 17005 expect(type, expected); |
| 17006 } |
| 17007 } |
| 17008 |
| 17096 void _resolveTestUnit(String code) { | 17009 void _resolveTestUnit(String code) { |
| 17097 testCode = code; | 17010 testCode = code; |
| 17098 testSource = addSource(testCode); | 17011 testSource = addSource(testCode); |
| 17099 LibraryElement library = resolve2(testSource); | 17012 LibraryElement library = resolve2(testSource); |
| 17100 assertNoErrors(testSource); | 17013 assertNoErrors(testSource); |
| 17101 verify([testSource]); | 17014 verify([testSource]); |
| 17102 testUnit = resolveCompilationUnit(testSource, library); | 17015 testUnit = resolveCompilationUnit(testSource, library); |
| 17103 } | 17016 } |
| 17104 } | 17017 } |
| OLD | NEW |