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

Unified Diff: pkg/front_end/lib/src/fasta/type_inference/type_inferrer.dart

Issue 2913743003: Change the approach of front_end top level inference to match the spec. (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/type_inference/type_inferrer.dart
diff --git a/pkg/front_end/lib/src/fasta/type_inference/type_inferrer.dart b/pkg/front_end/lib/src/fasta/type_inference/type_inferrer.dart
index 863ebfbdf83e3fd281a2dbca4b1a089a0b665e70..c5d9d0d29cfa048642c9a31486df5a3792d8de78 100644
--- a/pkg/front_end/lib/src/fasta/type_inference/type_inferrer.dart
+++ b/pkg/front_end/lib/src/fasta/type_inference/type_inferrer.dart
@@ -147,9 +147,6 @@ abstract class TypeInferrer {
/// performed--this is used for testing.
String get uri;
- /// Gets the [FieldNode] corresponding to the given [readTarget], if any.
- FieldNode getFieldNodeForReadTarget(Member readTarget);
-
/// Performs full type inference on the given field initializer.
void inferFieldInitializer(DartType declaredType, Expression initializer);
@@ -176,7 +173,7 @@ abstract class TypeInferrerImpl extends TypeInferrer {
/// Indicates whether the construct we are currently performing inference for
/// is outside of a method body, and hence top level type inference rules
/// should apply.
- final bool isTopLevel = false;
+ final bool isTopLevel;
final CoreTypes coreTypes;
@@ -200,7 +197,8 @@ abstract class TypeInferrerImpl extends TypeInferrer {
strongMode = engine.strongMode,
classHierarchy = engine.classHierarchy,
instrumentation = topLevel ? null : engine.instrumentation,
- typeSchemaEnvironment = engine.typeSchemaEnvironment;
+ typeSchemaEnvironment = engine.typeSchemaEnvironment,
+ isTopLevel = topLevel;
/// Gets the type promoter that should be used to promote types during
/// inference.
@@ -370,25 +368,29 @@ abstract class TypeInferrerImpl extends TypeInferrer {
new List<DartType>.filled(
calleeTypeParameters.length, const DynamicType()));
}
- int i = 0;
- _forEachArgument(arguments, (name, expression) {
- DartType formalType = name != null
- ? getNamedParameterType(calleeType, name)
- : getPositionalParameterType(calleeType, i++);
- DartType inferredFormalType = substitution != null
- ? substitution.substituteType(formalType)
- : formalType;
- var expressionType = inferExpression(expression, inferredFormalType,
- inferenceNeeded || isOverloadedArithmeticOperator);
- if (inferenceNeeded) {
- formalTypes.add(formalType);
- actualTypes.add(expressionType);
- }
- if (isOverloadedArithmeticOperator) {
- returnType = typeSchemaEnvironment.getTypeOfOverloadedArithmetic(
- receiverType, expressionType);
- }
- });
+ // TODO(paulberry): if we are doing top level inference and type arguments
+ // were omitted, report an error.
+ if (inferenceNeeded || !isTopLevel) {
+ int i = 0;
+ _forEachArgument(arguments, (name, expression) {
+ DartType formalType = name != null
+ ? getNamedParameterType(calleeType, name)
+ : getPositionalParameterType(calleeType, i++);
+ DartType inferredFormalType = substitution != null
+ ? substitution.substituteType(formalType)
+ : formalType;
+ var expressionType = inferExpression(expression, inferredFormalType,
+ inferenceNeeded || isOverloadedArithmeticOperator);
+ if (inferenceNeeded) {
+ formalTypes.add(formalType);
+ actualTypes.add(expressionType);
+ }
+ if (isOverloadedArithmeticOperator) {
+ returnType = typeSchemaEnvironment.getTypeOfOverloadedArithmetic(
+ receiverType, expressionType);
+ }
+ });
+ }
if (inferenceNeeded) {
typeSchemaEnvironment.inferGenericFunctionOrType(
returnType,

Powered by Google App Engine
This is Rietveld 408576698