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

Unified Diff: pkg/analyzer/lib/src/task/strong_mode.dart

Issue 2832893002: Issue 29398. Infer instance members using InheritanceManager of the ClassElement. (Closed)
Patch Set: Created 3 years, 8 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 | « pkg/analyzer/lib/src/task/dart.dart ('k') | pkg/analyzer/test/src/summary/top_level_inference_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/analyzer/lib/src/task/strong_mode.dart
diff --git a/pkg/analyzer/lib/src/task/strong_mode.dart b/pkg/analyzer/lib/src/task/strong_mode.dart
index e803d2df487c4b6dcb65b3e944076c980100d294..af0d650ae21aaa090da71a85bc03c7edd3163e6c 100644
--- a/pkg/analyzer/lib/src/task/strong_mode.dart
+++ b/pkg/analyzer/lib/src/task/strong_mode.dart
@@ -41,6 +41,11 @@ void setFieldType(VariableElement field, DartType newType) {
}
/**
+ * A function that return the [InheritanceManager] for the class [element].
+ */
+typedef InheritanceManager InheritanceManagerProvider(ClassElement element);
+
+/**
* A function that returns `true` if the given [element] passes the filter.
*/
typedef bool VariableFilter(VariableElement element);
@@ -61,9 +66,9 @@ class InstanceMemberInferrer {
TypeSystem typeSystem;
/**
- * The inheritance manager used to find overridden method.
+ * The provider for inheritance managers used to find overridden method.
*/
- final InheritanceManager inheritanceManager;
+ final InheritanceManagerProvider inheritanceManagerProvider;
/**
* The set of fields for which type inference from initializer should be
@@ -82,7 +87,9 @@ class InstanceMemberInferrer {
/**
* Initialize a newly create inferrer.
*/
- InstanceMemberInferrer(TypeProvider typeProvider, this.inheritanceManager,
+ InstanceMemberInferrer(
+ TypeProvider typeProvider,
+ this.inheritanceManagerProvider,
this.fieldsWithDisabledInitializerInference,
{TypeSystem typeSystem})
: typeSystem = (typeSystem != null)
@@ -118,7 +125,7 @@ class InstanceMemberInferrer {
* value is never `null`, but might be an error, and/or have the `null` type.
*/
_FieldOverrideInferenceResult _computeFieldOverrideType(
- PropertyAccessorElement accessor) {
+ InheritanceManager inheritanceManager, PropertyAccessorElement accessor) {
String name = accessor.displayName;
var overriddenElements = <ExecutableElement>[];
@@ -255,7 +262,8 @@ class InstanceMemberInferrer {
* If the given [element] represents a non-synthetic instance property
* accessor for which no type was provided, infer its types.
*/
- void _inferAccessor(PropertyAccessorElement element) {
+ void _inferAccessor(
+ InheritanceManager inheritanceManager, PropertyAccessorElement element) {
if (element.isSynthetic || element.isStatic) {
return;
}
@@ -265,7 +273,7 @@ class InstanceMemberInferrer {
}
_FieldOverrideInferenceResult typeResult =
- _computeFieldOverrideType(element);
+ _computeFieldOverrideType(inheritanceManager, element);
if (typeResult.isError == null || typeResult.type == null) {
return;
}
@@ -303,6 +311,8 @@ class InstanceMemberInferrer {
throw new _CycleException();
}
try {
+ InheritanceManager inheritanceManager =
+ inheritanceManagerProvider(classElement);
//
// Ensure that all of instance members in the supertypes have had types
// inferred for them.
@@ -313,9 +323,15 @@ class InstanceMemberInferrer {
//
// Then infer the types for the members.
//
- classElement.fields.forEach(_inferField);
- classElement.accessors.forEach(_inferAccessor);
- classElement.methods.forEach(_inferExecutable);
+ classElement.fields.forEach((field) {
+ _inferField(inheritanceManager, field);
+ });
+ classElement.accessors.forEach((accessor) {
+ _inferAccessor(inheritanceManager, accessor);
+ });
+ classElement.methods.forEach((method) {
+ _inferExecutable(inheritanceManager, method);
+ });
//
// Infer initializing formal parameter types. This must happen after
// field types are inferred.
@@ -345,7 +361,8 @@ class InstanceMemberInferrer {
* getter or setter, infer the return type and any parameter type(s) where
* they were not provided.
*/
- void _inferExecutable(ExecutableElement element) {
+ void _inferExecutable(
+ InheritanceManager inheritanceManager, ExecutableElement element) {
if (element.isSynthetic || element.isStatic) {
return;
}
@@ -396,13 +413,13 @@ class InstanceMemberInferrer {
* If the given [field] represents a non-synthetic instance field for
* which no type was provided, infer the type of the field.
*/
- void _inferField(FieldElement field) {
+ void _inferField(InheritanceManager inheritanceManager, FieldElement field) {
if (field.isSynthetic || field.isStatic) {
return;
}
_FieldOverrideInferenceResult typeResult =
- _computeFieldOverrideType(field.getter);
+ _computeFieldOverrideType(inheritanceManager, field.getter);
if (typeResult.isError) {
if (field is FieldElementForLink_ClassField) {
field.setInferenceError(new TopLevelInferenceErrorBuilder(
« no previous file with comments | « pkg/analyzer/lib/src/task/dart.dart ('k') | pkg/analyzer/test/src/summary/top_level_inference_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698