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

Side by Side Diff: pkg/analyzer/test/generated/resolver_test.dart

Issue 1609093003: fixes #25482, flatten Futures in strong mode so Future.then works (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 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 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
109 */ 109 */
110 static InternalAnalysisContext initContextWithCore( 110 static InternalAnalysisContext initContextWithCore(
111 InternalAnalysisContext context) { 111 InternalAnalysisContext context) {
112 DirectoryBasedDartSdk sdk = new _AnalysisContextFactory_initContextWithCore( 112 DirectoryBasedDartSdk sdk = new _AnalysisContextFactory_initContextWithCore(
113 new JavaFile("/fake/sdk"), 113 new JavaFile("/fake/sdk"),
114 enableAsync: context.analysisOptions.enableAsync); 114 enableAsync: context.analysisOptions.enableAsync);
115 SourceFactory sourceFactory = 115 SourceFactory sourceFactory =
116 new SourceFactory([new DartUriResolver(sdk), new FileUriResolver()]); 116 new SourceFactory([new DartUriResolver(sdk), new FileUriResolver()]);
117 context.sourceFactory = sourceFactory; 117 context.sourceFactory = sourceFactory;
118 AnalysisContext coreContext = sdk.context; 118 AnalysisContext coreContext = sdk.context;
119 (coreContext.analysisOptions as AnalysisOptionsImpl).strongMode =
120 context.analysisOptions.strongMode;
119 // 121 //
120 // dart:core 122 // dart:core
121 // 123 //
122 TestTypeProvider provider = new TestTypeProvider(); 124 TestTypeProvider provider = new TestTypeProvider();
123 CompilationUnitElementImpl coreUnit = 125 CompilationUnitElementImpl coreUnit =
124 new CompilationUnitElementImpl("core.dart"); 126 new CompilationUnitElementImpl("core.dart");
125 Source coreSource = sourceFactory.forUri(DartSdk.DART_CORE); 127 Source coreSource = sourceFactory.forUri(DartSdk.DART_CORE);
126 coreContext.setContents(coreSource, ""); 128 coreContext.setContents(coreSource, "");
127 coreUnit.librarySource = coreUnit.source = coreSource; 129 coreUnit.librarySource = coreUnit.source = coreSource;
128 ClassElementImpl proxyClassElement = ElementFactory.classElement2("_Proxy"); 130 ClassElementImpl proxyClassElement = ElementFactory.classElement2("_Proxy");
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
182 ]; 184 ];
183 LibraryElementImpl coreLibrary = new LibraryElementImpl.forNode( 185 LibraryElementImpl coreLibrary = new LibraryElementImpl.forNode(
184 coreContext, AstFactory.libraryIdentifier2(["dart", "core"])); 186 coreContext, AstFactory.libraryIdentifier2(["dart", "core"]));
185 coreLibrary.definingCompilationUnit = coreUnit; 187 coreLibrary.definingCompilationUnit = coreUnit;
186 // 188 //
187 // dart:async 189 // dart:async
188 // 190 //
189 Source asyncSource; 191 Source asyncSource;
190 LibraryElementImpl asyncLibrary; 192 LibraryElementImpl asyncLibrary;
191 if (context.analysisOptions.enableAsync) { 193 if (context.analysisOptions.enableAsync) {
194 asyncLibrary = new LibraryElementImpl.forNode(
195 coreContext, AstFactory.libraryIdentifier2(["dart", "async"]));
192 CompilationUnitElementImpl asyncUnit = 196 CompilationUnitElementImpl asyncUnit =
193 new CompilationUnitElementImpl("async.dart"); 197 new CompilationUnitElementImpl("async.dart");
194 asyncSource = sourceFactory.forUri(DartSdk.DART_ASYNC); 198 asyncSource = sourceFactory.forUri(DartSdk.DART_ASYNC);
195 coreContext.setContents(asyncSource, ""); 199 coreContext.setContents(asyncSource, "");
196 asyncUnit.librarySource = asyncUnit.source = asyncSource; 200 asyncUnit.librarySource = asyncUnit.source = asyncSource;
201 asyncLibrary.definingCompilationUnit = asyncUnit;
197 // Future 202 // Future
198 ClassElementImpl futureElement = 203 ClassElementImpl futureElement =
199 ElementFactory.classElement2("Future", ["T"]); 204 ElementFactory.classElement2("Future", ["T"]);
205 futureElement.enclosingElement = asyncUnit;
200 // factory Future.value([value]) 206 // factory Future.value([value])
201 ConstructorElementImpl futureConstructor = 207 ConstructorElementImpl futureConstructor =
202 ElementFactory.constructorElement2(futureElement, "value"); 208 ElementFactory.constructorElement2(futureElement, "value");
203 futureConstructor.parameters = <ParameterElement>[ 209 futureConstructor.parameters = <ParameterElement>[
204 ElementFactory.positionalParameter2("value", provider.dynamicType) 210 ElementFactory.positionalParameter2("value", provider.dynamicType)
205 ]; 211 ];
206 futureConstructor.factory = true; 212 futureConstructor.factory = true;
207 futureElement.constructors = <ConstructorElement>[futureConstructor]; 213 futureElement.constructors = <ConstructorElement>[futureConstructor];
208 // Future then(onValue(T value), { Function onError }); 214 // Future then(onValue(T value), { Function onError });
209 TypeDefiningElement futureThenR = DynamicElementImpl.instance; 215 TypeDefiningElement futureThenR = DynamicElementImpl.instance;
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
265 listenParamFunction.type = new FunctionTypeImpl(listenParamFunction); 271 listenParamFunction.type = new FunctionTypeImpl(listenParamFunction);
266 ParameterElementImpl listenParam = listenMethod.parameters[0]; 272 ParameterElementImpl listenParam = listenMethod.parameters[0];
267 listenParam.type = listenParamFunction.type; 273 listenParam.type = listenParamFunction.type;
268 274
269 asyncUnit.types = <ClassElement>[ 275 asyncUnit.types = <ClassElement>[
270 completerElement, 276 completerElement,
271 futureElement, 277 futureElement,
272 streamElement, 278 streamElement,
273 streamSubscriptionElement 279 streamSubscriptionElement
274 ]; 280 ];
275 asyncLibrary = new LibraryElementImpl.forNode(
276 coreContext, AstFactory.libraryIdentifier2(["dart", "async"]));
277 asyncLibrary.definingCompilationUnit = asyncUnit;
278 } 281 }
279 // 282 //
280 // dart:html 283 // dart:html
281 // 284 //
282 CompilationUnitElementImpl htmlUnit = 285 CompilationUnitElementImpl htmlUnit =
283 new CompilationUnitElementImpl("html_dartium.dart"); 286 new CompilationUnitElementImpl("html_dartium.dart");
284 Source htmlSource = sourceFactory.forUri(DartSdk.DART_HTML); 287 Source htmlSource = sourceFactory.forUri(DartSdk.DART_HTML);
285 coreContext.setContents(htmlSource, ""); 288 coreContext.setContents(htmlSource, "");
286 htmlUnit.librarySource = htmlUnit.source = htmlSource; 289 htmlUnit.librarySource = htmlUnit.source = htmlSource;
287 ClassElementImpl elementElement = ElementFactory.classElement2("Element"); 290 ClassElementImpl elementElement = ElementFactory.classElement2("Element");
(...skipping 9841 matching lines...) Expand 10 before | Expand all | Expand 10 after
10129 /** 10132 /**
10130 * The analyzer being used to analyze the test cases. 10133 * The analyzer being used to analyze the test cases.
10131 */ 10134 */
10132 StaticTypeAnalyzer _analyzer; 10135 StaticTypeAnalyzer _analyzer;
10133 10136
10134 /** 10137 /**
10135 * The type provider used to access the types. 10138 * The type provider used to access the types.
10136 */ 10139 */
10137 TestTypeProvider _typeProvider; 10140 TestTypeProvider _typeProvider;
10138 10141
10142 /**
10143 * The type system used to analyze the test cases.
10144 */
10145 TypeSystem get _typeSystem => _visitor.typeSystem;
10146
10139 void fail_visitFunctionExpressionInvocation() { 10147 void fail_visitFunctionExpressionInvocation() {
10140 fail("Not yet tested"); 10148 fail("Not yet tested");
10141 _listener.assertNoErrors(); 10149 _listener.assertNoErrors();
10142 } 10150 }
10143 10151
10144 void fail_visitMethodInvocation() { 10152 void fail_visitMethodInvocation() {
10145 fail("Not yet tested"); 10153 fail("Not yet tested");
10146 _listener.assertNoErrors(); 10154 _listener.assertNoErrors();
10147 } 10155 }
10148 10156
10149 void fail_visitSimpleIdentifier() { 10157 void fail_visitSimpleIdentifier() {
10150 fail("Not yet tested"); 10158 fail("Not yet tested");
10151 _listener.assertNoErrors(); 10159 _listener.assertNoErrors();
10152 } 10160 }
10153 10161
10154 @override 10162 @override
10155 void setUp() { 10163 void setUp() {
10156 super.setUp(); 10164 super.setUp();
10157 _listener = new GatheringErrorListener(); 10165 _listener = new GatheringErrorListener();
10158 _typeProvider = new TestTypeProvider();
10159 _analyzer = _createAnalyzer(); 10166 _analyzer = _createAnalyzer();
10160 } 10167 }
10161 10168
10162 void test_flatten_derived() { 10169 void test_flatten_derived() {
10163 // class Derived<T> extends Future<T> { ... } 10170 // class Derived<T> extends Future<T> { ... }
10164 ClassElementImpl derivedClass = 10171 ClassElementImpl derivedClass =
10165 ElementFactory.classElement2('Derived', ['T']); 10172 ElementFactory.classElement2('Derived', ['T']);
10166 derivedClass.supertype = _typeProvider.futureType 10173 derivedClass.supertype = _typeProvider.futureType
10167 .substitute4([derivedClass.typeParameters[0].type]); 10174 .substitute4([derivedClass.typeParameters[0].type]);
10168 InterfaceType intType = _typeProvider.intType; 10175 InterfaceType intType = _typeProvider.intType;
(...skipping 1245 matching lines...) Expand 10 before | Expand all | Expand 10 after
11414 InternalAnalysisContext context = AnalysisContextFactory.contextWithCore(); 11421 InternalAnalysisContext context = AnalysisContextFactory.contextWithCore();
11415 FileBasedSource source = 11422 FileBasedSource source =
11416 new FileBasedSource(FileUtilities2.createFile("/lib.dart")); 11423 new FileBasedSource(FileUtilities2.createFile("/lib.dart"));
11417 CompilationUnitElementImpl definingCompilationUnit = 11424 CompilationUnitElementImpl definingCompilationUnit =
11418 new CompilationUnitElementImpl("lib.dart"); 11425 new CompilationUnitElementImpl("lib.dart");
11419 definingCompilationUnit.librarySource = 11426 definingCompilationUnit.librarySource =
11420 definingCompilationUnit.source = source; 11427 definingCompilationUnit.source = source;
11421 LibraryElementImpl definingLibrary = 11428 LibraryElementImpl definingLibrary =
11422 new LibraryElementImpl.forNode(context, null); 11429 new LibraryElementImpl.forNode(context, null);
11423 definingLibrary.definingCompilationUnit = definingCompilationUnit; 11430 definingLibrary.definingCompilationUnit = definingCompilationUnit;
11431 _typeProvider = new TestTypeProvider(context);
11424 _visitor = new ResolverVisitor( 11432 _visitor = new ResolverVisitor(
11425 definingLibrary, source, _typeProvider, _listener, 11433 definingLibrary, source, _typeProvider, _listener,
11426 nameScope: new LibraryScope(definingLibrary, _listener)); 11434 nameScope: new LibraryScope(definingLibrary, _listener));
11427 _visitor.overrideManager.enterScope(); 11435 _visitor.overrideManager.enterScope();
11428 try { 11436 try {
11429 return _visitor.typeAnalyzer; 11437 return _visitor.typeAnalyzer;
11430 } catch (exception) { 11438 } catch (exception) {
11431 throw new IllegalArgumentException( 11439 throw new IllegalArgumentException(
11432 "Could not create analyzer", exception); 11440 "Could not create analyzer", exception);
11433 } 11441 }
11434 } 11442 }
11435 11443
11436 DartType _flatten(DartType type) => 11444 DartType _flatten(DartType type) => type.flattenFutures(_typeSystem);
11437 StaticTypeAnalyzer.flattenFutures(_typeProvider, type);
11438 11445
11439 /** 11446 /**
11440 * Return a simple identifier that has been resolved to a variable element wit h the given type. 11447 * Return a simple identifier that has been resolved to a variable element wit h the given type.
11441 * 11448 *
11442 * @param type the type of the variable being represented 11449 * @param type the type of the variable being represented
11443 * @param variableName the name of the variable 11450 * @param variableName the name of the variable
11444 * @return a simple identifier that has been resolved to a variable element wi th the given type 11451 * @return a simple identifier that has been resolved to a variable element wi th the given type
11445 */ 11452 */
11446 SimpleIdentifier _propagatedVariable( 11453 SimpleIdentifier _propagatedVariable(
11447 InterfaceType type, String variableName) { 11454 InterfaceType type, String variableName) {
(...skipping 2127 matching lines...) Expand 10 before | Expand all | Expand 10 after
13575 expect(m1.staticInvokeType.toString(), '((dynamic) → dynamic) → dynamic'); 13582 expect(m1.staticInvokeType.toString(), '((dynamic) → dynamic) → dynamic');
13576 expect(map1.staticType.toString(), '<T>((dynamic) → T) → T'); 13583 expect(map1.staticType.toString(), '<T>((dynamic) → T) → T');
13577 expect(map1.propagatedType, isNull); 13584 expect(map1.propagatedType, isNull);
13578 SimpleIdentifier map2 = _findIdentifier('map((e) => 3);'); 13585 SimpleIdentifier map2 = _findIdentifier('map((e) => 3);');
13579 MethodInvocation m2 = map2.parent; 13586 MethodInvocation m2 = map2.parent;
13580 expect(m2.staticInvokeType.toString(), '((dynamic) → int) → int'); 13587 expect(m2.staticInvokeType.toString(), '((dynamic) → int) → int');
13581 expect(map2.staticType.toString(), '<T>((dynamic) → T) → T'); 13588 expect(map2.staticType.toString(), '<T>((dynamic) → T) → T');
13582 expect(map2.propagatedType, isNull); 13589 expect(map2.propagatedType, isNull);
13583 } 13590 }
13584 13591
13592 void test_genericMethod_max_doubleDouble() {
13593 String code = r'''
13594 import 'dart:math';
13595 main() {
13596 var foo = max(1.0, 2.0);
13597 }
13598 ''';
13599 _resolveTestUnit(code);
13600
13601 SimpleIdentifier identifier = _findIdentifier('foo');
13602 VariableDeclaration declaration =
13603 identifier.getAncestor((node) => node is VariableDeclaration);
13604 expect(declaration.initializer.staticType.name, 'double');
13605 expect(declaration.initializer.propagatedType, isNull);
13606 }
13607
13608 void test_genericMethod_max_doubleDouble_prefixed() {
13609 String code = r'''
13610 import 'dart:math' as math;
13611 main() {
13612 var foo = math.max(1.0, 2.0);
13613 }
13614 ''';
13615 _resolveTestUnit(code);
13616
13617 SimpleIdentifier identifier = _findIdentifier('foo');
13618 VariableDeclaration declaration =
13619 identifier.getAncestor((node) => node is VariableDeclaration);
13620 expect(declaration.initializer.staticType.name, 'double');
13621 expect(declaration.initializer.propagatedType, isNull);
13622 }
13623
13624 void test_genericMethod_max_doubleInt() {
13625 String code = r'''
13626 import 'dart:math';
13627 main() {
13628 var foo = max(1.0, 2);
13629 }
13630 ''';
13631 _resolveTestUnit(code);
13632
13633 SimpleIdentifier identifier = _findIdentifier('foo');
13634 VariableDeclaration declaration =
13635 identifier.getAncestor((node) => node is VariableDeclaration);
13636 expect(declaration.initializer.staticType.name, 'num');
13637 expect(declaration.initializer.propagatedType, isNull);
13638 }
13639
13640 void test_genericMethod_max_intDouble() {
13641 String code = r'''
13642 import 'dart:math';
13643 main() {
13644 var foo = max(1, 2.0);
13645 }
13646 ''';
13647 _resolveTestUnit(code);
13648
13649 SimpleIdentifier identifier = _findIdentifier('foo');
13650 VariableDeclaration declaration =
13651 identifier.getAncestor((node) => node is VariableDeclaration);
13652 expect(declaration.initializer.staticType.name, 'num');
13653 expect(declaration.initializer.propagatedType, isNull);
13654 }
13655
13656 void test_genericMethod_max_intInt() {
13657 String code = r'''
13658 import 'dart:math';
13659 main() {
13660 var foo = max(1, 2);
13661 }
13662 ''';
13663 _resolveTestUnit(code);
13664
13665 SimpleIdentifier identifier = _findIdentifier('foo');
13666 VariableDeclaration declaration =
13667 identifier.getAncestor((node) => node is VariableDeclaration);
13668 expect(declaration.initializer.staticType.name, 'int');
13669 expect(declaration.initializer.propagatedType, isNull);
13670 }
13671
13585 void test_genericMethod_nestedCapture() { 13672 void test_genericMethod_nestedCapture() {
13586 _resolveTestUnit(r''' 13673 _resolveTestUnit(r'''
13587 class C<T> { 13674 class C<T> {
13588 /*=T*/ f/*<S>*/(/*=S*/ x) { 13675 /*=T*/ f/*<S>*/(/*=S*/ x) {
13589 new C<S>().f/*<int>*/(3); 13676 new C<S>().f/*<int>*/(3);
13590 new C<S>().f; // tear-off 13677 new C<S>().f; // tear-off
13591 return null; 13678 return null;
13592 } 13679 }
13593 } 13680 }
13594 '''); 13681 ''');
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after
13760 expect(_findIdentifier('staticFieldTearOff').staticType.toString(), 13847 expect(_findIdentifier('staticFieldTearOff').staticType.toString(),
13761 "<T>(T) → T"); 13848 "<T>(T) → T");
13762 expect( 13849 expect(
13763 _findIdentifier('topFunTearOff').staticType.toString(), "<T>(T) → T"); 13850 _findIdentifier('topFunTearOff').staticType.toString(), "<T>(T) → T");
13764 expect( 13851 expect(
13765 _findIdentifier('topFieldTearOff').staticType.toString(), "<T>(T) → T"); 13852 _findIdentifier('topFieldTearOff').staticType.toString(), "<T>(T) → T");
13766 expect(_findIdentifier('localTearOff').staticType.toString(), "<T>(T) → T"); 13853 expect(_findIdentifier('localTearOff').staticType.toString(), "<T>(T) → T");
13767 expect(_findIdentifier('paramTearOff').staticType.toString(), "<T>(T) → T"); 13854 expect(_findIdentifier('paramTearOff').staticType.toString(), "<T>(T) → T");
13768 } 13855 }
13769 13856
13770 void test_pseudoGeneric_max_doubleDouble() { 13857 void test_genericMethod_then() {
13771 String code = r'''
13772 import 'dart:math';
13773 main() {
13774 var foo = max(1.0, 2.0);
13775 }
13776 ''';
13777 _resolveTestUnit(code);
13778
13779 SimpleIdentifier identifier = _findIdentifier('foo');
13780 VariableDeclaration declaration =
13781 identifier.getAncestor((node) => node is VariableDeclaration);
13782 expect(declaration.initializer.staticType.name, 'double');
13783 expect(declaration.initializer.propagatedType, isNull);
13784 }
13785
13786 void test_pseudoGeneric_max_doubleDouble_prefixed() {
13787 String code = r'''
13788 import 'dart:math' as math;
13789 main() {
13790 var foo = math.max(1.0, 2.0);
13791 }
13792 ''';
13793 _resolveTestUnit(code);
13794
13795 SimpleIdentifier identifier = _findIdentifier('foo');
13796 VariableDeclaration declaration =
13797 identifier.getAncestor((node) => node is VariableDeclaration);
13798 expect(declaration.initializer.staticType.name, 'double');
13799 expect(declaration.initializer.propagatedType, isNull);
13800 }
13801
13802 void test_pseudoGeneric_max_doubleInt() {
13803 String code = r'''
13804 import 'dart:math';
13805 main() {
13806 var foo = max(1.0, 2);
13807 }
13808 ''';
13809 _resolveTestUnit(code);
13810
13811 SimpleIdentifier identifier = _findIdentifier('foo');
13812 VariableDeclaration declaration =
13813 identifier.getAncestor((node) => node is VariableDeclaration);
13814 expect(declaration.initializer.staticType.name, 'num');
13815 expect(declaration.initializer.propagatedType, isNull);
13816 }
13817
13818 void test_pseudoGeneric_max_intDouble() {
13819 String code = r'''
13820 import 'dart:math';
13821 main() {
13822 var foo = max(1, 2.0);
13823 }
13824 ''';
13825 _resolveTestUnit(code);
13826
13827 SimpleIdentifier identifier = _findIdentifier('foo');
13828 VariableDeclaration declaration =
13829 identifier.getAncestor((node) => node is VariableDeclaration);
13830 expect(declaration.initializer.staticType.name, 'num');
13831 expect(declaration.initializer.propagatedType, isNull);
13832 }
13833
13834 void test_pseudoGeneric_max_intInt() {
13835 String code = r'''
13836 import 'dart:math';
13837 main() {
13838 var foo = max(1, 2);
13839 }
13840 ''';
13841 _resolveTestUnit(code);
13842
13843 SimpleIdentifier identifier = _findIdentifier('foo');
13844 VariableDeclaration declaration =
13845 identifier.getAncestor((node) => node is VariableDeclaration);
13846 expect(declaration.initializer.staticType.name, 'int');
13847 expect(declaration.initializer.propagatedType, isNull);
13848 }
13849
13850 void test_pseudoGeneric_then() {
13851 String code = r''' 13858 String code = r'''
13852 import 'dart:async'; 13859 import 'dart:async';
13853 String toString(int x) => x.toString(); 13860 String toString(int x) => x.toString();
13854 main() { 13861 main() {
13855 Future<int> bar = null; 13862 Future<int> bar = null;
13856 var foo = bar.then(toString); 13863 var foo = bar.then(toString);
13857 } 13864 }
13858 '''; 13865 ''';
13859 _resolveTestUnit(code); 13866 _resolveTestUnit(code);
13860 13867
13861 SimpleIdentifier identifier = _findIdentifier('foo'); 13868 SimpleIdentifier identifier = _findIdentifier('foo');
13862 VariableDeclaration declaration = 13869 VariableDeclaration declaration =
13863 identifier.getAncestor((node) => node is VariableDeclaration); 13870 identifier.getAncestor((node) => node is VariableDeclaration);
13864 13871
13865 expect(declaration.initializer.staticType.toString(), "Future<String>"); 13872 expect(declaration.initializer.staticType.toString(), "Future<String>");
13866 expect(declaration.initializer.propagatedType, isNull); 13873 expect(declaration.initializer.propagatedType, isNull);
13867 } 13874 }
13868 13875
13869 void test_pseudoGeneric_then_prefixed() { 13876 void test_genericMethod_then_prefixed() {
13870 String code = r''' 13877 String code = r'''
13871 import 'dart:async' as async; 13878 import 'dart:async' as async;
13872 String toString(int x) => x.toString(); 13879 String toString(int x) => x.toString();
13873 main() { 13880 main() {
13874 async.Future<int> bar = null; 13881 async.Future<int> bar = null;
13875 var foo = bar.then(toString); 13882 var foo = bar.then(toString);
13876 } 13883 }
13877 '''; 13884 ''';
13878 _resolveTestUnit(code); 13885 _resolveTestUnit(code);
13879 13886
13880 SimpleIdentifier identifier = _findIdentifier('foo'); 13887 SimpleIdentifier identifier = _findIdentifier('foo');
13881 VariableDeclaration declaration = 13888 VariableDeclaration declaration =
13882 identifier.getAncestor((node) => node is VariableDeclaration); 13889 identifier.getAncestor((node) => node is VariableDeclaration);
13883 13890
13884 expect(declaration.initializer.staticType.toString(), "Future<String>"); 13891 expect(declaration.initializer.staticType.toString(), "Future<String>");
13885 expect(declaration.initializer.propagatedType, isNull); 13892 expect(declaration.initializer.propagatedType, isNull);
13886 } 13893 }
13887 13894
13895 void test_genericMethod_then_propagatedType() {
13896 // Regression test for https://github.com/dart-lang/sdk/issues/25482.
13897 String code = r'''
13898 import 'dart:async';
13899 void main() {
13900 Future<String> p;
13901 var foo = p.then((r) => new Future<String>.value(3));
13902 }
13903 ''';
13904 // This should produce no hints or warnings.
13905 _resolveTestUnit(code);
13906 VariableDeclaration foo = _findIdentifier('foo').parent;
13907 expect(foo.initializer.staticType.toString(), "Future<String>");
13908 expect(foo.initializer.propagatedType, isNull);
13909 }
13910
13888 void test_setterWithDynamicTypeIsError() { 13911 void test_setterWithDynamicTypeIsError() {
13889 Source source = addSource(r''' 13912 Source source = addSource(r'''
13890 class A { 13913 class A {
13891 dynamic set f(String s) => null; 13914 dynamic set f(String s) => null;
13892 } 13915 }
13893 dynamic set g(int x) => null; 13916 dynamic set g(int x) => null;
13894 '''); 13917 ''');
13895 computeLibrarySourceErrors(source); 13918 computeLibrarySourceErrors(source);
13896 assertErrors(source, [ 13919 assertErrors(source, [
13897 StaticWarningCode.NON_VOID_RETURN_FOR_SETTER, 13920 StaticWarningCode.NON_VOID_RETURN_FOR_SETTER,
(...skipping 3005 matching lines...) Expand 10 before | Expand all | Expand 10 after
16903 16926
16904 void _resolveTestUnit(String code) { 16927 void _resolveTestUnit(String code) {
16905 testCode = code; 16928 testCode = code;
16906 testSource = addSource(testCode); 16929 testSource = addSource(testCode);
16907 LibraryElement library = resolve2(testSource); 16930 LibraryElement library = resolve2(testSource);
16908 assertNoErrors(testSource); 16931 assertNoErrors(testSource);
16909 verify([testSource]); 16932 verify([testSource]);
16910 testUnit = resolveCompilationUnit(testSource, library); 16933 testUnit = resolveCompilationUnit(testSource, library);
16911 } 16934 }
16912 } 16935 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698