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

Side by Side Diff: pkg/analyzer/lib/src/task/strong/checker.dart

Issue 1495263003: Allow return of Future in async function (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Rename duplicate tests Created 5 years 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
« no previous file with comments | « no previous file | pkg/analyzer/test/src/task/strong/checker_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2015, 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 // TODO(jmesserly): this was ported from package:dev_compiler, and needs to be 5 // TODO(jmesserly): this was ported from package:dev_compiler, and needs to be
6 // refactored to fit into analyzer. 6 // refactored to fit into analyzer.
7 library analyzer.src.task.strong.checker; 7 library analyzer.src.task.strong.checker;
8 8
9 import 'package:analyzer/analyzer.dart'; 9 import 'package:analyzer/analyzer.dart';
10 import 'package:analyzer/src/generated/ast.dart'; 10 import 'package:analyzer/src/generated/ast.dart';
(...skipping 595 matching lines...) Expand 10 before | Expand all | Expand 10 after
606 void _checkReturnOrYield(Expression expression, AstNode node, 606 void _checkReturnOrYield(Expression expression, AstNode node,
607 {bool yieldStar: false}) { 607 {bool yieldStar: false}) {
608 var body = node.getAncestor((n) => n is FunctionBody); 608 var body = node.getAncestor((n) => n is FunctionBody);
609 var type = rules.getExpectedReturnType(body, yieldStar: yieldStar); 609 var type = rules.getExpectedReturnType(body, yieldStar: yieldStar);
610 if (type == null) { 610 if (type == null) {
611 // We have a type mismatch: the async/async*/sync* modifier does 611 // We have a type mismatch: the async/async*/sync* modifier does
612 // not match the return or yield type. We should have already gotten an 612 // not match the return or yield type. We should have already gotten an
613 // analyzer error in this case. 613 // analyzer error in this case.
614 return; 614 return;
615 } 615 }
616 InterfaceType futureType = rules.provider.futureType;
617 DartType actualType = expression.staticType;
618 if (body.isAsynchronous &&
619 !body.isGenerator &&
620 actualType is InterfaceType &&
621 actualType.element == futureType.element) {
622 type = futureType.substitute4([type]);
623 }
616 // TODO(vsm): Enforce void or dynamic (to void?) when expression is null. 624 // TODO(vsm): Enforce void or dynamic (to void?) when expression is null.
617 if (expression != null) checkAssignment(expression, type); 625 if (expression != null) checkAssignment(expression, type);
618 } 626 }
619 627
620 @override 628 @override
621 void visitExpressionFunctionBody(ExpressionFunctionBody node) { 629 void visitExpressionFunctionBody(ExpressionFunctionBody node) {
622 _checkReturnOrYield(node.expression, node); 630 _checkReturnOrYield(node.expression, node);
623 node.visitChildren(this); 631 node.visitChildren(this);
624 } 632 }
625 633
(...skipping 416 matching lines...) Expand 10 before | Expand all | Expand 10 after
1042 } 1050 }
1043 } catch (e) { 1051 } catch (e) {
1044 // TODO(sigmund): remove this try-catch block (see issue #48). 1052 // TODO(sigmund): remove this try-catch block (see issue #48).
1045 } 1053 }
1046 if (baseMethod == null || baseMethod.isStatic) return null; 1054 if (baseMethod == null || baseMethod.isStatic) return null;
1047 return baseMethod.type; 1055 return baseMethod.type;
1048 } 1056 }
1049 ; 1057 ;
1050 return f; 1058 return f;
1051 } 1059 }
OLDNEW
« no previous file with comments | « no previous file | pkg/analyzer/test/src/task/strong/checker_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698