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/generated/ast.dart'; | 9 import 'package:analyzer/src/generated/ast.dart'; |
10 import 'package:analyzer/src/generated/element.dart'; | 10 import 'package:analyzer/src/generated/element.dart'; |
(...skipping 3057 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3068 verify([source]); | 3068 verify([source]); |
3069 } | 3069 } |
3070 | 3070 |
3071 void test_isNotDouble() { | 3071 void test_isNotDouble() { |
3072 Source source = addSource("var v = 1 is! double;"); | 3072 Source source = addSource("var v = 1 is! double;"); |
3073 resolve(source); | 3073 resolve(source); |
3074 assertErrors(source, [HintCode.IS_NOT_DOUBLE]); | 3074 assertErrors(source, [HintCode.IS_NOT_DOUBLE]); |
3075 verify([source]); | 3075 verify([source]); |
3076 } | 3076 } |
3077 | 3077 |
| 3078 void test_missingReturn_async() { |
| 3079 Source source = addSource(''' |
| 3080 import 'dart:async'; |
| 3081 Future<int> f() async {} |
| 3082 '''); |
| 3083 resolve(source); |
| 3084 assertErrors(source, [HintCode.MISSING_RETURN]); |
| 3085 verify([source]); |
| 3086 } |
| 3087 |
3078 void test_missingReturn_function() { | 3088 void test_missingReturn_function() { |
3079 Source source = addSource("int f() {}"); | 3089 Source source = addSource("int f() {}"); |
3080 resolve(source); | 3090 resolve(source); |
3081 assertErrors(source, [HintCode.MISSING_RETURN]); | 3091 assertErrors(source, [HintCode.MISSING_RETURN]); |
3082 verify([source]); | 3092 verify([source]); |
3083 } | 3093 } |
3084 | 3094 |
3085 void test_missingReturn_method() { | 3095 void test_missingReturn_method() { |
3086 Source source = addSource(r''' | 3096 Source source = addSource(r''' |
3087 class A { | 3097 class A { |
(...skipping 2976 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6064 expect(nonPrefixedElement, same(nonPrefixedType)); | 6074 expect(nonPrefixedElement, same(nonPrefixedType)); |
6065 } | 6075 } |
6066 } | 6076 } |
6067 | 6077 |
6068 @reflectiveTest | 6078 @reflectiveTest |
6069 class LibraryResolver2Test extends ResolverTestCase { | 6079 class LibraryResolver2Test extends ResolverTestCase { |
6070 LibraryResolver2 _resolver; | 6080 LibraryResolver2 _resolver; |
6071 | 6081 |
6072 Source _coreLibrarySource; | 6082 Source _coreLibrarySource; |
6073 | 6083 |
| 6084 Source _asyncLibrarySource; |
| 6085 |
6074 @override | 6086 @override |
6075 void setUp() { | 6087 void setUp() { |
6076 super.setUp(); | 6088 super.setUp(); |
6077 _resolver = new LibraryResolver2(analysisContext2); | 6089 _resolver = new LibraryResolver2(analysisContext2); |
6078 _coreLibrarySource = | 6090 _coreLibrarySource = |
6079 analysisContext2.sourceFactory.forUri(DartSdk.DART_CORE); | 6091 analysisContext2.sourceFactory.forUri(DartSdk.DART_CORE); |
| 6092 _asyncLibrarySource = |
| 6093 analysisContext2.sourceFactory.forUri(DartSdk.DART_ASYNC); |
6080 } | 6094 } |
6081 | 6095 |
6082 void test_imports_relative() { | 6096 void test_imports_relative() { |
6083 Source sourceA = addSource(r''' | 6097 Source sourceA = addSource(r''' |
6084 library libA; | 6098 library libA; |
6085 import 'libB.dart'; | 6099 import 'libB.dart'; |
6086 class A {}'''); | 6100 class A {}'''); |
6087 Source sourceB = addNamedSource("/libB.dart", r''' | 6101 Source sourceB = addNamedSource("/libB.dart", r''' |
6088 library libB; | 6102 library libB; |
6089 import 'test.dart | 6103 import 'test.dart |
6090 class B {}'''); | 6104 class B {}'''); |
6091 List<ResolvableLibrary> cycle = new List<ResolvableLibrary>(); | 6105 List<ResolvableLibrary> cycle = new List<ResolvableLibrary>(); |
6092 ResolvableLibrary coreLib = _createResolvableLibrary(_coreLibrarySource); | 6106 ResolvableLibrary coreLib = _createResolvableLibrary(_coreLibrarySource); |
6093 coreLib.libraryElement = analysisContext2.computeLibraryElement( | 6107 coreLib.libraryElement = analysisContext2.computeLibraryElement( |
6094 _coreLibrarySource) as LibraryElementImpl; | 6108 _coreLibrarySource) as LibraryElementImpl; |
| 6109 ResolvableLibrary asyncLib = _createResolvableLibrary(_asyncLibrarySource); |
| 6110 asyncLib.libraryElement = analysisContext2.computeLibraryElement( |
| 6111 _asyncLibrarySource) as LibraryElementImpl; |
6095 ResolvableLibrary libA = _createResolvableLibrary(sourceA); | 6112 ResolvableLibrary libA = _createResolvableLibrary(sourceA); |
6096 ResolvableLibrary libB = _createResolvableLibrary(sourceB); | 6113 ResolvableLibrary libB = _createResolvableLibrary(sourceB); |
6097 libA.importedLibraries = <ResolvableLibrary>[coreLib, libB]; | 6114 libA.importedLibraries = <ResolvableLibrary>[coreLib, asyncLib, libB]; |
6098 libB.importedLibraries = <ResolvableLibrary>[coreLib, libA]; | 6115 libB.importedLibraries = <ResolvableLibrary>[coreLib, asyncLib, libA]; |
6099 cycle.add(libA); | 6116 cycle.add(libA); |
6100 cycle.add(libB); | 6117 cycle.add(libB); |
6101 LibraryElement library = _resolver.resolveLibrary(sourceA, cycle); | 6118 LibraryElement library = _resolver.resolveLibrary(sourceA, cycle); |
6102 List<LibraryElement> importedLibraries = library.importedLibraries; | 6119 List<LibraryElement> importedLibraries = library.importedLibraries; |
6103 assertNamedElements(importedLibraries, ["dart.core", "libB"]); | 6120 assertNamedElements(importedLibraries, ["dart.core", "libB"]); |
6104 } | 6121 } |
6105 | 6122 |
6106 ResolvableLibrary _createResolvableLibrary(Source source) { | 6123 ResolvableLibrary _createResolvableLibrary(Source source) { |
6107 CompilationUnit unit = analysisContext2.parseCompilationUnit(source); | 6124 CompilationUnit unit = analysisContext2.parseCompilationUnit(source); |
6108 ResolvableLibrary resolvableLibrary = new ResolvableLibrary(source); | 6125 ResolvableLibrary resolvableLibrary = new ResolvableLibrary(source); |
(...skipping 6857 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
12966 // Create a mock library element with the types expected to be in dart:core. | 12983 // Create a mock library element with the types expected to be in dart:core. |
12967 // We cannot use either ElementFactory or TestTypeProvider (which uses | 12984 // We cannot use either ElementFactory or TestTypeProvider (which uses |
12968 // ElementFactory) because we side-effect the elements in ways that would | 12985 // ElementFactory) because we side-effect the elements in ways that would |
12969 // break other tests. | 12986 // break other tests. |
12970 // | 12987 // |
12971 InterfaceType objectType = _classElement("Object", null).type; | 12988 InterfaceType objectType = _classElement("Object", null).type; |
12972 InterfaceType boolType = _classElement("bool", objectType).type; | 12989 InterfaceType boolType = _classElement("bool", objectType).type; |
12973 InterfaceType numType = _classElement("num", objectType).type; | 12990 InterfaceType numType = _classElement("num", objectType).type; |
12974 InterfaceType doubleType = _classElement("double", numType).type; | 12991 InterfaceType doubleType = _classElement("double", numType).type; |
12975 InterfaceType functionType = _classElement("Function", objectType).type; | 12992 InterfaceType functionType = _classElement("Function", objectType).type; |
| 12993 InterfaceType futureType = _classElement("Future", objectType, ["T"]).type; |
12976 InterfaceType intType = _classElement("int", numType).type; | 12994 InterfaceType intType = _classElement("int", numType).type; |
12977 InterfaceType listType = _classElement("List", objectType, ["E"]).type; | 12995 InterfaceType listType = _classElement("List", objectType, ["E"]).type; |
12978 InterfaceType mapType = _classElement("Map", objectType, ["K", "V"]).type; | 12996 InterfaceType mapType = _classElement("Map", objectType, ["K", "V"]).type; |
12979 InterfaceType stackTraceType = _classElement("StackTrace", objectType).type; | 12997 InterfaceType stackTraceType = _classElement("StackTrace", objectType).type; |
12980 InterfaceType stringType = _classElement("String", objectType).type; | 12998 InterfaceType stringType = _classElement("String", objectType).type; |
12981 InterfaceType symbolType = _classElement("Symbol", objectType).type; | 12999 InterfaceType symbolType = _classElement("Symbol", objectType).type; |
12982 InterfaceType typeType = _classElement("Type", objectType).type; | 13000 InterfaceType typeType = _classElement("Type", objectType).type; |
12983 CompilationUnitElementImpl coreUnit = | 13001 CompilationUnitElementImpl coreUnit = |
12984 new CompilationUnitElementImpl("core.dart"); | 13002 new CompilationUnitElementImpl("core.dart"); |
12985 coreUnit.types = <ClassElement>[ | 13003 coreUnit.types = <ClassElement>[ |
12986 boolType.element, | 13004 boolType.element, |
12987 doubleType.element, | 13005 doubleType.element, |
12988 functionType.element, | 13006 functionType.element, |
12989 intType.element, | 13007 intType.element, |
12990 listType.element, | 13008 listType.element, |
12991 mapType.element, | 13009 mapType.element, |
12992 objectType.element, | 13010 objectType.element, |
12993 stackTraceType.element, | 13011 stackTraceType.element, |
12994 stringType.element, | 13012 stringType.element, |
12995 symbolType.element, | 13013 symbolType.element, |
12996 typeType.element]; | 13014 typeType.element]; |
| 13015 CompilationUnitElementImpl asyncUnit = |
| 13016 new CompilationUnitElementImpl("async.dart"); |
| 13017 asyncUnit.types = <ClassElement>[futureType.element]; |
| 13018 AnalysisContextImpl context = new AnalysisContextImpl(); |
12997 LibraryElementImpl coreLibrary = new LibraryElementImpl.forNode( | 13019 LibraryElementImpl coreLibrary = new LibraryElementImpl.forNode( |
12998 new AnalysisContextImpl(), | 13020 context, |
12999 AstFactory.libraryIdentifier2(["dart.core"])); | 13021 AstFactory.libraryIdentifier2(["dart.core"])); |
13000 coreLibrary.definingCompilationUnit = coreUnit; | 13022 coreLibrary.definingCompilationUnit = coreUnit; |
| 13023 LibraryElementImpl asyncLibrary = new LibraryElementImpl.forNode( |
| 13024 context, |
| 13025 AstFactory.libraryIdentifier2(["dart.async"])); |
| 13026 asyncLibrary.definingCompilationUnit = asyncUnit; |
13001 // | 13027 // |
13002 // Create a type provider and ensure that it can return the expected types. | 13028 // Create a type provider and ensure that it can return the expected types. |
13003 // | 13029 // |
13004 TypeProviderImpl provider = new TypeProviderImpl(coreLibrary); | 13030 TypeProviderImpl provider = new TypeProviderImpl(coreLibrary, asyncLibrary); |
13005 expect(provider.boolType, same(boolType)); | 13031 expect(provider.boolType, same(boolType)); |
13006 expect(provider.bottomType, isNotNull); | 13032 expect(provider.bottomType, isNotNull); |
13007 expect(provider.doubleType, same(doubleType)); | 13033 expect(provider.doubleType, same(doubleType)); |
13008 expect(provider.dynamicType, isNotNull); | 13034 expect(provider.dynamicType, isNotNull); |
13009 expect(provider.functionType, same(functionType)); | 13035 expect(provider.functionType, same(functionType)); |
| 13036 expect(provider.futureType, same(futureType)); |
13010 expect(provider.intType, same(intType)); | 13037 expect(provider.intType, same(intType)); |
13011 expect(provider.listType, same(listType)); | 13038 expect(provider.listType, same(listType)); |
13012 expect(provider.mapType, same(mapType)); | 13039 expect(provider.mapType, same(mapType)); |
13013 expect(provider.objectType, same(objectType)); | 13040 expect(provider.objectType, same(objectType)); |
13014 expect(provider.stackTraceType, same(stackTraceType)); | 13041 expect(provider.stackTraceType, same(stackTraceType)); |
13015 expect(provider.stringType, same(stringType)); | 13042 expect(provider.stringType, same(stringType)); |
13016 expect(provider.symbolType, same(symbolType)); | 13043 expect(provider.symbolType, same(symbolType)); |
13017 expect(provider.typeType, same(typeType)); | 13044 expect(provider.typeType, same(typeType)); |
13018 } | 13045 } |
13019 | 13046 |
(...skipping 618 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
13638 // check propagated type | 13665 // check propagated type |
13639 FunctionType propagatedType = node.propagatedType as FunctionType; | 13666 FunctionType propagatedType = node.propagatedType as FunctionType; |
13640 expect(propagatedType.returnType, test.typeProvider.stringType); | 13667 expect(propagatedType.returnType, test.typeProvider.stringType); |
13641 } on AnalysisException catch (e, stackTrace) { | 13668 } on AnalysisException catch (e, stackTrace) { |
13642 thrownException[0] = new CaughtException(e, stackTrace); | 13669 thrownException[0] = new CaughtException(e, stackTrace); |
13643 } | 13670 } |
13644 } | 13671 } |
13645 return null; | 13672 return null; |
13646 } | 13673 } |
13647 } | 13674 } |
OLD | NEW |