| 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 10235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 10246 expect(type.typeFormals, isEmpty, | 10246 expect(type.typeFormals, isEmpty, |
| 10247 reason: 'this static method is not generic'); | 10247 reason: 'this static method is not generic'); |
| 10248 } | 10248 } |
| 10249 | 10249 |
| 10250 void test_staticMethods_classTypeParameters_genericMethod() { | 10250 void test_staticMethods_classTypeParameters_genericMethod() { |
| 10251 AnalysisOptionsImpl options = new AnalysisOptionsImpl(); | 10251 AnalysisOptionsImpl options = new AnalysisOptionsImpl(); |
| 10252 options.enableGenericMethods = true; | 10252 options.enableGenericMethods = true; |
| 10253 resetWithOptions(options); | 10253 resetWithOptions(options); |
| 10254 String code = r''' | 10254 String code = r''' |
| 10255 class C<T> { | 10255 class C<T> { |
| 10256 static void m<S>(S s) => null; | 10256 static void m<S>(S s) { |
| 10257 void f<U>(S s, U u) {} |
| 10258 print(f); |
| 10259 } |
| 10257 } | 10260 } |
| 10258 main() { | 10261 main() { |
| 10259 print(C.m); | 10262 print(C.m); |
| 10260 } | 10263 } |
| 10261 '''; | 10264 '''; |
| 10262 _resolveTestUnit(code); | 10265 _resolveTestUnit(code); |
| 10263 SimpleIdentifier identifier = _findIdentifier('m);'); | 10266 // C - m |
| 10264 FunctionTypeImpl type = identifier.staticType; | 10267 TypeParameterType typeS; |
| 10265 expect(type.toString(), '<S>(S) → void'); | 10268 { |
| 10266 expect(type.typeParameters, isEmpty, | 10269 SimpleIdentifier identifier = _findIdentifier('m);'); |
| 10267 reason: 'static methods should not have type parameters'); | 10270 FunctionTypeImpl type = identifier.staticType; |
| 10268 expect(type.typeArguments, isEmpty, | 10271 expect(type.toString(), '<S>(S) → void'); |
| 10269 reason: 'static methods should not have type arguments'); | 10272 expect(type.typeParameters, isEmpty, |
| 10270 expect(type.typeFormals.toString(), '[S]'); | 10273 reason: 'static methods should not have type parameters'); |
| 10274 expect(type.typeArguments, isEmpty, |
| 10275 reason: 'static methods should not have type arguments'); |
| 10276 expect(type.typeFormals.toString(), '[S]'); |
| 10277 typeS = type.typeFormals[0].type; |
| 10271 | 10278 |
| 10272 type = type.instantiate([DynamicTypeImpl.instance]); | 10279 type = type.instantiate([DynamicTypeImpl.instance]); |
| 10273 expect(type.toString(), '(dynamic) → void'); | 10280 expect(type.toString(), '(dynamic) → void'); |
| 10274 expect(type.typeParameters.toString(), '[S]'); | 10281 expect(type.typeParameters.toString(), '[S]'); |
| 10275 expect(type.typeArguments, [DynamicTypeImpl.instance]); | 10282 expect(type.typeArguments, [DynamicTypeImpl.instance]); |
| 10276 expect(type.typeFormals, isEmpty); | 10283 expect(type.typeFormals, isEmpty); |
| 10284 } |
| 10285 // C - m - f |
| 10286 { |
| 10287 SimpleIdentifier identifier = _findIdentifier('f);'); |
| 10288 FunctionTypeImpl type = identifier.staticType; |
| 10289 expect(type.toString(), '<U>(S, U) → void'); |
| 10290 expect(type.typeParameters.toString(), '[S]'); |
| 10291 expect(type.typeArguments.toString(), '[S]'); |
| 10292 expect(type.typeFormals.toString(), '[U]'); |
| 10293 |
| 10294 type = type.instantiate([DynamicTypeImpl.instance]); |
| 10295 expect(type.toString(), '(S, dynamic) → void'); |
| 10296 expect(type.typeParameters.toString(), '[S, U]'); |
| 10297 expect(type.typeArguments, [typeS, DynamicTypeImpl.instance]); |
| 10298 expect(type.typeFormals, isEmpty); |
| 10299 } |
| 10277 } | 10300 } |
| 10278 } | 10301 } |
| 10279 | 10302 |
| 10280 @reflectiveTest | 10303 @reflectiveTest |
| 10281 class StaticTypeAnalyzerTest extends EngineTestCase { | 10304 class StaticTypeAnalyzerTest extends EngineTestCase { |
| 10282 /** | 10305 /** |
| 10283 * The error listener to which errors will be reported. | 10306 * The error listener to which errors will be reported. |
| 10284 */ | 10307 */ |
| 10285 GatheringErrorListener _listener; | 10308 GatheringErrorListener _listener; |
| 10286 | 10309 |
| (...skipping 6808 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 17095 | 17118 |
| 17096 void _resolveTestUnit(String code) { | 17119 void _resolveTestUnit(String code) { |
| 17097 testCode = code; | 17120 testCode = code; |
| 17098 testSource = addSource(testCode); | 17121 testSource = addSource(testCode); |
| 17099 LibraryElement library = resolve2(testSource); | 17122 LibraryElement library = resolve2(testSource); |
| 17100 assertNoErrors(testSource); | 17123 assertNoErrors(testSource); |
| 17101 verify([testSource]); | 17124 verify([testSource]); |
| 17102 testUnit = resolveCompilationUnit(testSource, library); | 17125 testUnit = resolveCompilationUnit(testSource, library); |
| 17103 } | 17126 } |
| 17104 } | 17127 } |
| OLD | NEW |