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

Unified Diff: pkg/front_end/lib/src/fasta/kernel/kernel_shadow_ast.dart

Issue 2888073003: Fix a type inference corner case: return expression where void expected. (Closed)
Patch Set: 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
Index: pkg/front_end/lib/src/fasta/kernel/kernel_shadow_ast.dart
diff --git a/pkg/front_end/lib/src/fasta/kernel/kernel_shadow_ast.dart b/pkg/front_end/lib/src/fasta/kernel/kernel_shadow_ast.dart
index f4894c98dd1f26be9a6b34238f04e61207924f7c..45b41b39184a5099257fec64f481f06c1f3488ae 100644
--- a/pkg/front_end/lib/src/fasta/kernel/kernel_shadow_ast.dart
+++ b/pkg/front_end/lib/src/fasta/kernel/kernel_shadow_ast.dart
@@ -455,12 +455,13 @@ class KernelFunctionExpression extends FunctionExpression
inferrer.closureContext.inferredReturnType, isExpressionFunction);
if (!isExpressionFunction &&
returnContext != null &&
- !inferrer.typeSchemaEnvironment
- .isSubtypeOf(inferredReturnType, returnContext)) {
+ (!inferrer.typeSchemaEnvironment
+ .isSubtypeOf(inferredReturnType, returnContext) ||
+ returnContext is VoidType)) {
// For block-bodied functions, if the inferred return type isn't a
- // subtype of the context, we use the context. TODO(paulberry): this is
- // inherited from analyzer; it's not part of the spec. See also
- // dartbug.com/29606.
+ // subtype of the context (or the context is void), we use the context.
+ // TODO(paulberry): this is inherited from analyzer; it's not part of
+ // the spec. See also dartbug.com/29606.
inferredReturnType = greatestClosure(inferrer.coreTypes, returnContext);
}
« no previous file with comments | « pkg/analyzer/test/src/context/mock_sdk.dart ('k') | pkg/front_end/testcases/inference/block_bodied_lambdas_void_context.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698