| 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 engine.resolver_test; | 5 library engine.resolver_test; |
| 6 | 6 |
| 7 import 'dart:collection'; | 7 import 'dart:collection'; |
| 8 | 8 |
| 9 import 'package:analyzer/src/context/context.dart' as newContext; | 9 import 'package:analyzer/src/context/context.dart' as newContext; |
| 10 import 'package:analyzer/src/generated/ast.dart'; | 10 import 'package:analyzer/src/generated/ast.dart'; |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 61 runReflectiveTests(TypeProviderImplTest); | 61 runReflectiveTests(TypeProviderImplTest); |
| 62 runReflectiveTests(TypeResolverVisitorTest); | 62 runReflectiveTests(TypeResolverVisitorTest); |
| 63 runReflectiveTests(CheckedModeCompileTimeErrorCodeTest); | 63 runReflectiveTests(CheckedModeCompileTimeErrorCodeTest); |
| 64 runReflectiveTests(ErrorResolverTest); | 64 runReflectiveTests(ErrorResolverTest); |
| 65 runReflectiveTests(HintCodeTest); | 65 runReflectiveTests(HintCodeTest); |
| 66 runReflectiveTests(MemberMapTest); | 66 runReflectiveTests(MemberMapTest); |
| 67 runReflectiveTests(NonHintCodeTest); | 67 runReflectiveTests(NonHintCodeTest); |
| 68 runReflectiveTests(SimpleResolverTest); | 68 runReflectiveTests(SimpleResolverTest); |
| 69 runReflectiveTests(StrictModeTest); | 69 runReflectiveTests(StrictModeTest); |
| 70 runReflectiveTests(TypePropagationTest); | 70 runReflectiveTests(TypePropagationTest); |
| 71 runReflectiveTests(StrongModeStaticTypeAnalyzer2Test); |
| 71 runReflectiveTests(StrongModeTypePropagationTest); | 72 runReflectiveTests(StrongModeTypePropagationTest); |
| 72 } | 73 } |
| 73 | 74 |
| 74 /** | 75 /** |
| 75 * The class `AnalysisContextFactory` defines utility methods used to create ana
lysis contexts | 76 * The class `AnalysisContextFactory` defines utility methods used to create ana
lysis contexts |
| 76 * for testing purposes. | 77 * for testing purposes. |
| 77 */ | 78 */ |
| 78 class AnalysisContextFactory { | 79 class AnalysisContextFactory { |
| 79 static String _DART_MATH = "dart:math"; | 80 static String _DART_MATH = "dart:math"; |
| 80 | 81 |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 186 // dart:async | 187 // dart:async |
| 187 // | 188 // |
| 188 CompilationUnitElementImpl asyncUnit = | 189 CompilationUnitElementImpl asyncUnit = |
| 189 new CompilationUnitElementImpl("async.dart"); | 190 new CompilationUnitElementImpl("async.dart"); |
| 190 Source asyncSource = sourceFactory.forUri(DartSdk.DART_ASYNC); | 191 Source asyncSource = sourceFactory.forUri(DartSdk.DART_ASYNC); |
| 191 coreContext.setContents(asyncSource, ""); | 192 coreContext.setContents(asyncSource, ""); |
| 192 asyncUnit.librarySource = asyncUnit.source = asyncSource; | 193 asyncUnit.librarySource = asyncUnit.source = asyncSource; |
| 193 // Future | 194 // Future |
| 194 ClassElementImpl futureElement = | 195 ClassElementImpl futureElement = |
| 195 ElementFactory.classElement2("Future", ["T"]); | 196 ElementFactory.classElement2("Future", ["T"]); |
| 196 InterfaceType futureType = futureElement.type; | |
| 197 // factory Future.value([value]) | 197 // factory Future.value([value]) |
| 198 ConstructorElementImpl futureConstructor = | 198 ConstructorElementImpl futureConstructor = |
| 199 ElementFactory.constructorElement2(futureElement, "value"); | 199 ElementFactory.constructorElement2(futureElement, "value"); |
| 200 futureConstructor.parameters = <ParameterElement>[ | 200 futureConstructor.parameters = <ParameterElement>[ |
| 201 ElementFactory.positionalParameter2("value", provider.dynamicType) | 201 ElementFactory.positionalParameter2("value", provider.dynamicType) |
| 202 ]; | 202 ]; |
| 203 futureConstructor.factory = true; | 203 futureConstructor.factory = true; |
| 204 (futureConstructor.type as FunctionTypeImpl).typeArguments = | 204 (futureConstructor.type as FunctionTypeImpl).typeArguments = |
| 205 futureElement.type.typeArguments; | 205 futureElement.type.typeArguments; |
| 206 futureElement.constructors = <ConstructorElement>[futureConstructor]; | 206 futureElement.constructors = <ConstructorElement>[futureConstructor]; |
| 207 // Future then(onValue(T value), { Function onError }); | 207 // Future then(onValue(T value), { Function onError }); |
| 208 List<ParameterElement> parameters = <ParameterElement>[ | 208 List<ParameterElement> parameters = <ParameterElement>[ |
| 209 ElementFactory.requiredParameter2( | 209 ElementFactory.requiredParameter2( |
| 210 "value", futureElement.typeParameters[0].type) | 210 "value", futureElement.typeParameters[0].type) |
| 211 ]; | 211 ]; |
| 212 FunctionTypeAliasElementImpl aliasElement = | 212 FunctionTypeAliasElementImpl aliasElement = |
| 213 new FunctionTypeAliasElementImpl.forNode(null); | 213 new FunctionTypeAliasElementImpl.forNode(null); |
| 214 aliasElement.synthetic = true; | 214 aliasElement.synthetic = true; |
| 215 aliasElement.parameters = parameters; | 215 aliasElement.parameters = parameters; |
| 216 aliasElement.returnType = provider.dynamicType; | 216 aliasElement.returnType = provider.dynamicType; |
| 217 aliasElement.enclosingElement = asyncUnit; | 217 aliasElement.enclosingElement = asyncUnit; |
| 218 FunctionTypeImpl aliasType = new FunctionTypeImpl.forTypedef(aliasElement); | 218 FunctionTypeImpl aliasType = new FunctionTypeImpl.forTypedef(aliasElement); |
| 219 aliasElement.shareTypeParameters(futureElement.typeParameters); | 219 aliasElement.shareTypeParameters(futureElement.typeParameters); |
| 220 aliasType.typeArguments = futureElement.type.typeArguments; | 220 aliasType.typeArguments = futureElement.type.typeArguments; |
| 221 DartType futureDynamicType = |
| 222 futureElement.type.substitute4([provider.dynamicType]); |
| 221 MethodElement thenMethod = ElementFactory.methodElementWithParameters( | 223 MethodElement thenMethod = ElementFactory.methodElementWithParameters( |
| 222 "then", futureElement.type.typeArguments, futureType, [ | 224 "then", futureElement.type.typeArguments, futureDynamicType, [ |
| 223 ElementFactory.requiredParameter2("onValue", aliasType), | 225 ElementFactory.requiredParameter2("onValue", aliasType), |
| 224 ElementFactory.namedParameter2("onError", provider.functionType) | 226 ElementFactory.namedParameter2("onError", provider.functionType) |
| 225 ]); | 227 ]); |
| 226 futureElement.methods = <MethodElement>[thenMethod]; | 228 futureElement.methods = <MethodElement>[thenMethod]; |
| 227 // Completer | 229 // Completer |
| 228 ClassElementImpl completerElement = | 230 ClassElementImpl completerElement = |
| 229 ElementFactory.classElement2("Completer", ["T"]); | 231 ElementFactory.classElement2("Completer", ["T"]); |
| 230 ConstructorElementImpl completerConstructor = | 232 ConstructorElementImpl completerConstructor = |
| 231 ElementFactory.constructorElement2(completerElement, null); | 233 ElementFactory.constructorElement2(completerElement, null); |
| 232 (completerConstructor.type as FunctionTypeImpl).typeArguments = | 234 (completerConstructor.type as FunctionTypeImpl).typeArguments = |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 331 Source mathSource = sourceFactory.forUri(_DART_MATH); | 333 Source mathSource = sourceFactory.forUri(_DART_MATH); |
| 332 coreContext.setContents(mathSource, ""); | 334 coreContext.setContents(mathSource, ""); |
| 333 mathUnit.librarySource = mathUnit.source = mathSource; | 335 mathUnit.librarySource = mathUnit.source = mathSource; |
| 334 FunctionElement cosElement = ElementFactory.functionElement3( | 336 FunctionElement cosElement = ElementFactory.functionElement3( |
| 335 "cos", | 337 "cos", |
| 336 provider.doubleType.element, | 338 provider.doubleType.element, |
| 337 <ClassElement>[provider.numType.element], | 339 <ClassElement>[provider.numType.element], |
| 338 ClassElement.EMPTY_LIST); | 340 ClassElement.EMPTY_LIST); |
| 339 TopLevelVariableElement ln10Element = ElementFactory | 341 TopLevelVariableElement ln10Element = ElementFactory |
| 340 .topLevelVariableElement3("LN10", true, false, provider.doubleType); | 342 .topLevelVariableElement3("LN10", true, false, provider.doubleType); |
| 343 FunctionElement maxElement = ElementFactory.functionElement3( |
| 344 "max", |
| 345 provider.numType.element, |
| 346 <ClassElement>[provider.numType.element, provider.numType.element], |
| 347 ClassElement.EMPTY_LIST); |
| 341 TopLevelVariableElement piElement = ElementFactory.topLevelVariableElement3( | 348 TopLevelVariableElement piElement = ElementFactory.topLevelVariableElement3( |
| 342 "PI", true, false, provider.doubleType); | 349 "PI", true, false, provider.doubleType); |
| 343 ClassElementImpl randomElement = ElementFactory.classElement2("Random"); | 350 ClassElementImpl randomElement = ElementFactory.classElement2("Random"); |
| 344 randomElement.abstract = true; | 351 randomElement.abstract = true; |
| 345 ConstructorElementImpl randomConstructor = | 352 ConstructorElementImpl randomConstructor = |
| 346 ElementFactory.constructorElement2(randomElement, null); | 353 ElementFactory.constructorElement2(randomElement, null); |
| 347 randomConstructor.factory = true; | 354 randomConstructor.factory = true; |
| 348 ParameterElementImpl seedParam = new ParameterElementImpl("seed", 0); | 355 ParameterElementImpl seedParam = new ParameterElementImpl("seed", 0); |
| 349 seedParam.parameterKind = ParameterKind.POSITIONAL; | 356 seedParam.parameterKind = ParameterKind.POSITIONAL; |
| 350 seedParam.type = provider.intType; | 357 seedParam.type = provider.intType; |
| 351 randomConstructor.parameters = <ParameterElement>[seedParam]; | 358 randomConstructor.parameters = <ParameterElement>[seedParam]; |
| 352 randomElement.constructors = <ConstructorElement>[randomConstructor]; | 359 randomElement.constructors = <ConstructorElement>[randomConstructor]; |
| 353 FunctionElement sinElement = ElementFactory.functionElement3( | 360 FunctionElement sinElement = ElementFactory.functionElement3( |
| 354 "sin", | 361 "sin", |
| 355 provider.doubleType.element, | 362 provider.doubleType.element, |
| 356 <ClassElement>[provider.numType.element], | 363 <ClassElement>[provider.numType.element], |
| 357 ClassElement.EMPTY_LIST); | 364 ClassElement.EMPTY_LIST); |
| 358 FunctionElement sqrtElement = ElementFactory.functionElement3( | 365 FunctionElement sqrtElement = ElementFactory.functionElement3( |
| 359 "sqrt", | 366 "sqrt", |
| 360 provider.doubleType.element, | 367 provider.doubleType.element, |
| 361 <ClassElement>[provider.numType.element], | 368 <ClassElement>[provider.numType.element], |
| 362 ClassElement.EMPTY_LIST); | 369 ClassElement.EMPTY_LIST); |
| 363 mathUnit.accessors = <PropertyAccessorElement>[ | 370 mathUnit.accessors = <PropertyAccessorElement>[ |
| 364 ln10Element.getter, | 371 ln10Element.getter, |
| 365 piElement.getter | 372 piElement.getter |
| 366 ]; | 373 ]; |
| 367 mathUnit.functions = <FunctionElement>[cosElement, sinElement, sqrtElement]; | 374 mathUnit.functions = <FunctionElement>[ |
| 375 cosElement, |
| 376 maxElement, |
| 377 sinElement, |
| 378 sqrtElement |
| 379 ]; |
| 368 mathUnit.topLevelVariables = <TopLevelVariableElement>[ | 380 mathUnit.topLevelVariables = <TopLevelVariableElement>[ |
| 369 ln10Element, | 381 ln10Element, |
| 370 piElement | 382 piElement |
| 371 ]; | 383 ]; |
| 372 mathUnit.types = <ClassElement>[randomElement]; | 384 mathUnit.types = <ClassElement>[randomElement]; |
| 373 LibraryElementImpl mathLibrary = new LibraryElementImpl.forNode( | 385 LibraryElementImpl mathLibrary = new LibraryElementImpl.forNode( |
| 374 coreContext, AstFactory.libraryIdentifier2(["dart", "math"])); | 386 coreContext, AstFactory.libraryIdentifier2(["dart", "math"])); |
| 375 mathLibrary.definingCompilationUnit = mathUnit; | 387 mathLibrary.definingCompilationUnit = mathUnit; |
| 376 // | 388 // |
| 377 // Set empty sources for the rest of the libraries. | 389 // Set empty sources for the rest of the libraries. |
| (...skipping 9577 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 9955 } | 9967 } |
| 9956 } | 9968 } |
| 9957 } | 9969 } |
| 9958 | 9970 |
| 9959 class SourceContainer_ChangeSetTest_test_toString implements SourceContainer { | 9971 class SourceContainer_ChangeSetTest_test_toString implements SourceContainer { |
| 9960 @override | 9972 @override |
| 9961 bool contains(Source source) => false; | 9973 bool contains(Source source) => false; |
| 9962 } | 9974 } |
| 9963 | 9975 |
| 9964 /** | 9976 /** |
| 9977 * Shared infrastructure for [StaticTypeAnalyzer2Test] and |
| 9978 * [StrongModeStaticTypeAnalyzer2Test]. |
| 9979 */ |
| 9980 class _StaticTypeAnalyzer2TestShared extends ResolverTestCase { |
| 9981 String testCode; |
| 9982 Source testSource; |
| 9983 CompilationUnit testUnit; |
| 9984 |
| 9985 SimpleIdentifier _findIdentifier(String search) { |
| 9986 SimpleIdentifier identifier = EngineTestCase.findNode( |
| 9987 testUnit, testCode, search, (node) => node is SimpleIdentifier); |
| 9988 return identifier; |
| 9989 } |
| 9990 |
| 9991 void _resolveTestUnit(String code) { |
| 9992 testCode = code; |
| 9993 testSource = addSource(testCode); |
| 9994 LibraryElement library = resolve2(testSource); |
| 9995 assertNoErrors(testSource); |
| 9996 verify([testSource]); |
| 9997 testUnit = resolveCompilationUnit(testSource, library); |
| 9998 } |
| 9999 } |
| 10000 |
| 10001 /** |
| 9965 * Like [StaticTypeAnalyzerTest], but as end-to-end tests. | 10002 * Like [StaticTypeAnalyzerTest], but as end-to-end tests. |
| 9966 */ | 10003 */ |
| 9967 @reflectiveTest | 10004 @reflectiveTest |
| 9968 class StaticTypeAnalyzer2Test extends ResolverTestCase { | 10005 class StaticTypeAnalyzer2Test extends _StaticTypeAnalyzer2TestShared { |
| 9969 String testCode; | |
| 9970 Source testSource; | |
| 9971 CompilationUnit testUnit; | |
| 9972 | |
| 9973 void test_FunctionExpressionInvocation_block() { | 10006 void test_FunctionExpressionInvocation_block() { |
| 9974 String code = r''' | 10007 String code = r''' |
| 9975 main() { | 10008 main() { |
| 9976 var foo = (() { return 1; })(); | 10009 var foo = (() { return 1; })(); |
| 9977 } | 10010 } |
| 9978 '''; | 10011 '''; |
| 9979 _resolveTestUnit(code); | 10012 _resolveTestUnit(code); |
| 9980 SimpleIdentifier identifier = _findIdentifier('foo'); | 10013 SimpleIdentifier identifier = _findIdentifier('foo'); |
| 9981 VariableDeclaration declaration = | 10014 VariableDeclaration declaration = |
| 9982 identifier.getAncestor((node) => node is VariableDeclaration); | 10015 identifier.getAncestor((node) => node is VariableDeclaration); |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 10054 """; | 10087 """; |
| 10055 _resolveTestUnit(code); | 10088 _resolveTestUnit(code); |
| 10056 SimpleIdentifier identifier = _findIdentifier("p()"); | 10089 SimpleIdentifier identifier = _findIdentifier("p()"); |
| 10057 expect(identifier.staticType, DynamicTypeImpl.instance); | 10090 expect(identifier.staticType, DynamicTypeImpl.instance); |
| 10058 { | 10091 { |
| 10059 FunctionType type = identifier.propagatedType; | 10092 FunctionType type = identifier.propagatedType; |
| 10060 expect(type, isNotNull); | 10093 expect(type, isNotNull); |
| 10061 expect(type.name, 'Foo'); | 10094 expect(type.name, 'Foo'); |
| 10062 } | 10095 } |
| 10063 } | 10096 } |
| 10064 | |
| 10065 SimpleIdentifier _findIdentifier(String search) { | |
| 10066 SimpleIdentifier identifier = EngineTestCase.findNode( | |
| 10067 testUnit, testCode, search, (node) => node is SimpleIdentifier); | |
| 10068 return identifier; | |
| 10069 } | |
| 10070 | |
| 10071 void _resolveTestUnit(String code) { | |
| 10072 testCode = code; | |
| 10073 testSource = addSource(testCode); | |
| 10074 LibraryElement library = resolve2(testSource); | |
| 10075 assertNoErrors(testSource); | |
| 10076 verify([testSource]); | |
| 10077 testUnit = resolveCompilationUnit(testSource, library); | |
| 10078 } | |
| 10079 } | 10097 } |
| 10080 | 10098 |
| 10081 @reflectiveTest | 10099 @reflectiveTest |
| 10082 class StaticTypeAnalyzerTest extends EngineTestCase { | 10100 class StaticTypeAnalyzerTest extends EngineTestCase { |
| 10083 /** | 10101 /** |
| 10084 * The error listener to which errors will be reported. | 10102 * The error listener to which errors will be reported. |
| 10085 */ | 10103 */ |
| 10086 GatheringErrorListener _listener; | 10104 GatheringErrorListener _listener; |
| 10087 | 10105 |
| 10088 /** | 10106 /** |
| (...skipping 1790 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 11879 Source source = addSource(r''' | 11897 Source source = addSource(r''' |
| 11880 int f() { | 11898 int f() { |
| 11881 num n = 1234; | 11899 num n = 1234; |
| 11882 return n & 0x0F; | 11900 return n & 0x0F; |
| 11883 }'''); | 11901 }'''); |
| 11884 computeLibrarySourceErrors(source); | 11902 computeLibrarySourceErrors(source); |
| 11885 assertErrors(source, [StaticTypeWarningCode.UNDEFINED_OPERATOR]); | 11903 assertErrors(source, [StaticTypeWarningCode.UNDEFINED_OPERATOR]); |
| 11886 } | 11904 } |
| 11887 } | 11905 } |
| 11888 | 11906 |
| 11907 /** |
| 11908 * Strong mode static analyzer end to end tests |
| 11909 */ |
| 11910 @reflectiveTest |
| 11911 class StrongModeStaticTypeAnalyzer2Test extends _StaticTypeAnalyzer2TestShared { |
| 11912 void setUp() { |
| 11913 AnalysisOptionsImpl options = new AnalysisOptionsImpl(); |
| 11914 options.strongMode = true; |
| 11915 resetWithOptions(options); |
| 11916 } |
| 11917 |
| 11918 void test_ternaryOperator_null_right() { |
| 11919 String code = r''' |
| 11920 main() { |
| 11921 var foo = (true) ? 3 : null; |
| 11922 } |
| 11923 '''; |
| 11924 _resolveTestUnit(code); |
| 11925 |
| 11926 SimpleIdentifier identifier = _findIdentifier('foo'); |
| 11927 VariableDeclaration declaration = |
| 11928 identifier.getAncestor((node) => node is VariableDeclaration); |
| 11929 expect(declaration.initializer.staticType.name, 'int'); |
| 11930 expect(declaration.initializer.propagatedType, isNull); |
| 11931 } |
| 11932 |
| 11933 void test_ternaryOperator_null_left() { |
| 11934 String code = r''' |
| 11935 main() { |
| 11936 var foo = (true) ? null : 3; |
| 11937 } |
| 11938 '''; |
| 11939 _resolveTestUnit(code); |
| 11940 |
| 11941 SimpleIdentifier identifier = _findIdentifier('foo'); |
| 11942 VariableDeclaration declaration = |
| 11943 identifier.getAncestor((node) => node is VariableDeclaration); |
| 11944 expect(declaration.initializer.staticType.name, 'int'); |
| 11945 expect(declaration.initializer.propagatedType, isNull); |
| 11946 } |
| 11947 |
| 11948 void test_dynamicObjectMethod_toString() { |
| 11949 String code = r''' |
| 11950 main() { |
| 11951 dynamic a = null; |
| 11952 var foo = a.toString(); |
| 11953 } |
| 11954 '''; |
| 11955 _resolveTestUnit(code); |
| 11956 |
| 11957 SimpleIdentifier identifier = _findIdentifier('foo'); |
| 11958 VariableDeclaration declaration = |
| 11959 identifier.getAncestor((node) => node is VariableDeclaration); |
| 11960 expect(declaration.initializer.staticType.name, 'String'); |
| 11961 expect(declaration.initializer.propagatedType, isNull); |
| 11962 } |
| 11963 |
| 11964 void test_dynamicObjectGetter_hashCode() { |
| 11965 String code = r''' |
| 11966 main() { |
| 11967 dynamic a = null; |
| 11968 var foo = a.hashCode; |
| 11969 } |
| 11970 '''; |
| 11971 _resolveTestUnit(code); |
| 11972 |
| 11973 SimpleIdentifier identifier = _findIdentifier('foo'); |
| 11974 VariableDeclaration declaration = |
| 11975 identifier.getAncestor((node) => node is VariableDeclaration); |
| 11976 expect(declaration.initializer.staticType.name, 'int'); |
| 11977 expect(declaration.initializer.propagatedType, isNull); |
| 11978 } |
| 11979 |
| 11980 void test_pseudoGeneric_max_intInt() { |
| 11981 String code = r''' |
| 11982 import 'dart:math'; |
| 11983 main() { |
| 11984 var foo = max(1, 2); |
| 11985 } |
| 11986 '''; |
| 11987 _resolveTestUnit(code); |
| 11988 |
| 11989 SimpleIdentifier identifier = _findIdentifier('foo'); |
| 11990 VariableDeclaration declaration = |
| 11991 identifier.getAncestor((node) => node is VariableDeclaration); |
| 11992 expect(declaration.initializer.staticType.name, 'int'); |
| 11993 expect(declaration.initializer.propagatedType, isNull); |
| 11994 } |
| 11995 |
| 11996 void test_pseudoGeneric_max_doubleDouble() { |
| 11997 String code = r''' |
| 11998 import 'dart:math'; |
| 11999 main() { |
| 12000 var foo = max(1.0, 2.0); |
| 12001 } |
| 12002 '''; |
| 12003 _resolveTestUnit(code); |
| 12004 |
| 12005 SimpleIdentifier identifier = _findIdentifier('foo'); |
| 12006 VariableDeclaration declaration = |
| 12007 identifier.getAncestor((node) => node is VariableDeclaration); |
| 12008 expect(declaration.initializer.staticType.name, 'double'); |
| 12009 expect(declaration.initializer.propagatedType, isNull); |
| 12010 } |
| 12011 |
| 12012 void test_pseudoGeneric_max_intDouble() { |
| 12013 String code = r''' |
| 12014 import 'dart:math'; |
| 12015 main() { |
| 12016 var foo = max(1, 2.0); |
| 12017 } |
| 12018 '''; |
| 12019 _resolveTestUnit(code); |
| 12020 |
| 12021 SimpleIdentifier identifier = _findIdentifier('foo'); |
| 12022 VariableDeclaration declaration = |
| 12023 identifier.getAncestor((node) => node is VariableDeclaration); |
| 12024 expect(declaration.initializer.staticType.name, 'num'); |
| 12025 expect(declaration.initializer.propagatedType, isNull); |
| 12026 } |
| 12027 |
| 12028 void test_pseudoGeneric_then() { |
| 12029 String code = r''' |
| 12030 import 'dart:async'; |
| 12031 String toString(int x) => x.toString(); |
| 12032 main() { |
| 12033 Future<int> bar = null; |
| 12034 var foo = bar.then(toString); |
| 12035 } |
| 12036 '''; |
| 12037 _resolveTestUnit(code); |
| 12038 |
| 12039 SimpleIdentifier identifier = _findIdentifier('foo'); |
| 12040 VariableDeclaration declaration = |
| 12041 identifier.getAncestor((node) => node is VariableDeclaration); |
| 12042 InterfaceType stringType = typeProvider.stringType; |
| 12043 InterfaceType futureType = typeProvider.futureType; |
| 12044 InterfaceType futureOfStringType = |
| 12045 futureType.substitute4(<DartType>[stringType]); |
| 12046 |
| 12047 expect(declaration.initializer.staticType.toString(), "Future<String>"); |
| 12048 expect(declaration.initializer.propagatedType, isNull); |
| 12049 } |
| 12050 } |
| 12051 |
| 11889 @reflectiveTest | 12052 @reflectiveTest |
| 11890 class StrongModeTypePropagationTest extends ResolverTestCase { | 12053 class StrongModeTypePropagationTest extends ResolverTestCase { |
| 11891 @override | 12054 @override |
| 11892 void setUp() { | 12055 void setUp() { |
| 11893 AnalysisOptionsImpl options = new AnalysisOptionsImpl(); | 12056 AnalysisOptionsImpl options = new AnalysisOptionsImpl(); |
| 11894 options.strongMode = true; | 12057 options.strongMode = true; |
| 11895 resetWithOptions(options); | 12058 resetWithOptions(options); |
| 11896 } | 12059 } |
| 11897 | 12060 |
| 11898 void test_foreachInference_dynamic_disabled() { | 12061 void test_foreachInference_dynamic_disabled() { |
| (...skipping 2658 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 14557 // check propagated type | 14720 // check propagated type |
| 14558 FunctionType propagatedType = node.propagatedType as FunctionType; | 14721 FunctionType propagatedType = node.propagatedType as FunctionType; |
| 14559 expect(propagatedType.returnType, test.typeProvider.stringType); | 14722 expect(propagatedType.returnType, test.typeProvider.stringType); |
| 14560 } on AnalysisException catch (e, stackTrace) { | 14723 } on AnalysisException catch (e, stackTrace) { |
| 14561 thrownException[0] = new CaughtException(e, stackTrace); | 14724 thrownException[0] = new CaughtException(e, stackTrace); |
| 14562 } | 14725 } |
| 14563 } | 14726 } |
| 14564 return null; | 14727 return null; |
| 14565 } | 14728 } |
| 14566 } | 14729 } |
| OLD | NEW |