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

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

Issue 2908453002: Infer the types of initializing formals from the corresponding fields. (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_inference_engine.dart
diff --git a/pkg/front_end/lib/src/fasta/type_inference/type_inference_engine.dart b/pkg/front_end/lib/src/fasta/type_inference/type_inference_engine.dart
index ddba0420a3ede29e90ee044e41ca199310fc203e..2fcb7faa010550e164394713f346f2a7aa4118f2 100644
--- a/pkg/front_end/lib/src/fasta/type_inference/type_inference_engine.dart
+++ b/pkg/front_end/lib/src/fasta/type_inference/type_inference_engine.dart
@@ -8,7 +8,7 @@ import 'package:front_end/src/fasta/kernel/kernel_shadow_ast.dart';
import 'package:front_end/src/fasta/type_inference/type_inference_listener.dart';
import 'package:front_end/src/fasta/type_inference/type_inferrer.dart';
import 'package:front_end/src/fasta/type_inference/type_schema_environment.dart';
-import 'package:kernel/ast.dart' show DartType, DynamicType;
+import 'package:kernel/ast.dart' show Class, DartType, DynamicType;
import 'package:kernel/class_hierarchy.dart';
import 'package:kernel/core_types.dart';
@@ -71,6 +71,10 @@ abstract class TypeInferenceEngine {
/// Records that the given [field] will need top level type inference.
void recordField(KernelField field);
+
+ /// Records that the given initializing [formal] will need top level type
+ /// inference.
+ void recordInitializingFormal(KernelVariableDeclaration formal);
}
/// Derived class containing generic implementations of
@@ -86,6 +90,8 @@ abstract class TypeInferenceEngineImpl extends TypeInferenceEngine {
final fieldNodes = <FieldNode>[];
+ final initializingFormals = <KernelVariableDeclaration>[];
+
@override
CoreTypes coreTypes;
@@ -105,12 +111,27 @@ abstract class TypeInferenceEngineImpl extends TypeInferenceEngine {
/// Queries whether the given [field] has an initializer.
bool fieldHasInitializer(KernelField field);
+ DartType _inferInitializingFormalType(KernelVariableDeclaration formal) {
+ assert(KernelVariableDeclaration.isImplicitlyTyped(formal));
+ Class enclosingClass = formal.parent.parent.parent;
+ for (var field in enclosingClass.fields) {
+ if (field.name.name == formal.name) {
+ return field.type;
+ }
+ }
+ // No matching field. The error should be reported elsewhere.
+ return const DynamicType();
+ }
+
@override
void finishTopLevel() {
for (var fieldNode in fieldNodes) {
if (fieldNode.isEvaluated) continue;
new _FieldWalker().walk(fieldNode);
}
+ for (var formal in initializingFormals) {
+ formal.type = _inferInitializingFormalType(formal);
+ }
}
/// Gets the declared type of the given [field], or `null` if the type is
@@ -182,6 +203,11 @@ abstract class TypeInferenceEngineImpl extends TypeInferenceEngine {
fieldNodes.add(createFieldNode(field));
}
+ @override
+ void recordInitializingFormal(KernelVariableDeclaration formal) {
+ initializingFormals.add(formal);
+ }
+
/// Stores [inferredType] as the inferred type of [field].
void setFieldInferredType(KernelField field, DartType inferredType);
}

Powered by Google App Engine
This is Rietveld 408576698