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

Unified Diff: pkg/analyzer/lib/src/generated/error_verifier.dart

Issue 2870063002: Allowing `e` of any type in `void f(...) => e` (Closed)
Patch Set: There was no test for the block case, added that Created 3 years, 7 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | tests/language/void_arrow_return_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/analyzer/lib/src/generated/error_verifier.dart
diff --git a/pkg/analyzer/lib/src/generated/error_verifier.dart b/pkg/analyzer/lib/src/generated/error_verifier.dart
index ce1dfe702f438e83d9493bd27671865965180383..f8a9177bf6be18b66157a50c187d595de2ea631a 100644
--- a/pkg/analyzer/lib/src/generated/error_verifier.dart
+++ b/pkg/analyzer/lib/src/generated/error_verifier.dart
@@ -660,7 +660,8 @@ class ErrorVerifier extends RecursiveAstVisitor<Object> {
function is PropertyAccessorElement &&
function.isSetter;
if (!isSetterWithImplicitReturn) {
- _checkForReturnOfInvalidType(node.expression, expectedReturnType);
+ _checkForReturnOfInvalidType(node.expression, expectedReturnType,
+ isArrowFunction: true);
}
return super.visitExpressionFunctionBody(node);
} finally {
@@ -5598,7 +5599,8 @@ class ErrorVerifier extends RecursiveAstVisitor<Object> {
* See [StaticTypeWarningCode.RETURN_OF_INVALID_TYPE].
*/
void _checkForReturnOfInvalidType(
- Expression returnExpression, DartType expectedReturnType) {
+ Expression returnExpression, DartType expectedReturnType,
+ {bool isArrowFunction = false}) {
if (_enclosingFunction == null) {
return;
}
@@ -5610,6 +5612,10 @@ class ErrorVerifier extends RecursiveAstVisitor<Object> {
}
DartType staticReturnType = _computeReturnTypeForMethod(returnExpression);
if (expectedReturnType.isVoid) {
+ if (isArrowFunction) {
+ // "void f(..) => e" admits all types for "e".
+ return;
+ }
if (staticReturnType.isVoid ||
staticReturnType.isDynamic ||
staticReturnType.isBottom ||
« no previous file with comments | « no previous file | tests/language/void_arrow_return_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698