Skip to content

Commit

Permalink
[cfe] Implement new async return rules
Browse files Browse the repository at this point in the history
Closes #41800
Closes #41900
Closes #42134
Closes #42282
Closes #42236
Closes #42169

Change-Id: Ia994bc07fba4e2342fcb59d44fc77608198a328b
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/152150
Commit-Queue: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Dmitry Stefantsov <dmitryas@google.com>
  • Loading branch information
johnniwinther authored and commit-bot@chromium.org committed Jul 6, 2020
1 parent 3a4aad6 commit 34f5c9d
Show file tree
Hide file tree
Showing 34 changed files with 1,217 additions and 362 deletions.
20 changes: 20 additions & 0 deletions pkg/_fe_analyzer_shared/lib/src/messages/codes_generated.dart
Expand Up @@ -7541,6 +7541,26 @@ const MessageCode messageReturnWithoutExpression = const MessageCode(
severity: Severity.warning,
message: r"""Must explicitly return a value from a non-void function.""");

// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
const Code<Null> codeReturnWithoutExpressionAsync =
messageReturnWithoutExpressionAsync;

// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
const MessageCode messageReturnWithoutExpressionAsync = const MessageCode(
"ReturnWithoutExpressionAsync",
message:
r"""A value must be explicitly returned from a non-void async function.""");

// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
const Code<Null> codeReturnWithoutExpressionSync =
messageReturnWithoutExpressionSync;

// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
const MessageCode messageReturnWithoutExpressionSync = const MessageCode(
"ReturnWithoutExpressionSync",
message:
r"""A value must be explicitly returned from a non-void function.""");

// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
const Template<Message Function(Uri uri_)> templateSdkRootNotFound =
const Template<Message Function(Uri uri_)>(
Expand Down
2 changes: 1 addition & 1 deletion pkg/compiler/lib/src/ir/static_type_base.dart
Expand Up @@ -100,7 +100,7 @@ abstract class StaticTypeBase extends ir.Visitor<ir.DartType> {

@override
ir.DartType visitAwaitExpression(ir.AwaitExpression node) {
return typeEnvironment.unfutureType(visitNode(node.operand));
return typeEnvironment.flatten(visitNode(node.operand));
}

@override
Expand Down
2 changes: 1 addition & 1 deletion pkg/dev_compiler/lib/src/kernel/compiler.dart
Expand Up @@ -3125,7 +3125,7 @@ class ProgramCompiler extends ComputeOnceConstantVisitor<js_ast.Expression>
var gen = emitGeneratorFn((_) => []);
// Return type of an async body is `Future<flatten(T)>`, where T is the
// declared return type.
var returnType = _types.unfutureType(function
var returnType = _types.flatten(function
.computeThisFunctionType(_currentLibrary.nonNullable)
.returnType);
return js.call('#.async(#, #)',
Expand Down
4 changes: 2 additions & 2 deletions pkg/front_end/lib/src/fasta/kernel/inference_visitor.dart
Expand Up @@ -271,7 +271,7 @@ class InferenceVisitor
node.operand, typeContext, true,
isVoidAllowed: !inferrer.isNonNullableByDefault);
DartType inferredType =
inferrer.typeSchemaEnvironment.unfutureType(operandResult.inferredType);
inferrer.typeSchemaEnvironment.flatten(operandResult.inferredType);
node.operand = operandResult.expression..parent = node;
return new ExpressionInferenceResult(inferredType, node);
}
Expand Down Expand Up @@ -2161,7 +2161,7 @@ class InferenceVisitor
bool typeContextIsMap = node.keyType is! ImplicitTypeArgument;
bool typeContextIsIterable = false;
DartType unfuturedTypeContext =
inferrer.typeSchemaEnvironment.unfutureType(typeContext);
inferrer.typeSchemaEnvironment.flatten(typeContext);
if (!inferrer.isTopLevel && inferenceNeeded) {
// Ambiguous set/map literal
if (unfuturedTypeContext is InterfaceType) {
Expand Down

0 comments on commit 34f5c9d

Please sign in to comment.