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

Unified Diff: pkg/analyzer/lib/src/summary/link.dart

Issue 1957973002: Fix AST-based type inference of enum types. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 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
« no previous file with comments | « no previous file | pkg/analyzer/test/src/task/strong/inferred_type_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/analyzer/lib/src/summary/link.dart
diff --git a/pkg/analyzer/lib/src/summary/link.dart b/pkg/analyzer/lib/src/summary/link.dart
index 70ee163fb797bdfe4b31e8740233cbcd8f13e478..ae8bd48d2ebba55807afbf095a3412a8f4921006 100644
--- a/pkg/analyzer/lib/src/summary/link.dart
+++ b/pkg/analyzer/lib/src/summary/link.dart
@@ -432,7 +432,7 @@ class ClassElementForLink_Class extends ClassElementForLink
: super(enclosingElement);
@override
- List<PropertyAccessorElement> get accessors {
+ List<PropertyAccessorElementForLink> get accessors {
if (_accessors == null) {
_accessors = <PropertyAccessorElementForLink>[];
Map<String, SyntheticVariableElementForLink> syntheticVariables =
@@ -664,15 +664,22 @@ class ClassElementForLink_Enum extends ClassElementForLink {
InterfaceType _type;
List<FieldElementForLink_EnumField> _fields;
+ List<PropertyAccessorElementForLink> _accessors;
+ DartType _valuesType;
ClassElementForLink_Enum(
CompilationUnitElementForLink enclosingElement, this._unlinkedEnum)
: super(enclosingElement);
@override
- List<PropertyAccessorElement> get accessors {
- // TODO(paulberry): do we need to include synthetic accessors?
- return const [];
+ List<PropertyAccessorElementForLink> get accessors {
+ if (_accessors == null) {
+ _accessors = <PropertyAccessorElementForLink>[];
+ for (FieldElementForLink_EnumField field in fields) {
+ _accessors.add(field.getter);
+ }
+ }
+ return _accessors;
}
@override
@@ -720,6 +727,12 @@ class ClassElementForLink_Enum extends ClassElementForLink {
@override
ConstructorElementForLink get unnamedConstructor => null;
+ /**
+ * Get the type of the enum's static member `values`.
+ */
+ DartType get valuesType =>
+ _valuesType ??= library._linker.typeProvider.listType.instantiate([type]);
+
@override
DartType buildType(DartType getTypeArgument(int i),
List<int> implicitFunctionTypeIndices) =>
@@ -2572,12 +2585,18 @@ class FieldElementForLink_EnumField extends FieldElementForLink
*/
final UnlinkedEnumValue unlinkedEnumValue;
+ PropertyAccessorElementForLink_EnumField _getter;
+
@override
final ClassElementForLink_Enum enclosingElement;
FieldElementForLink_EnumField(this.unlinkedEnumValue, this.enclosingElement);
@override
+ PropertyAccessorElementForLink_EnumField get getter =>
+ _getter ??= new PropertyAccessorElementForLink_EnumField(this);
+
+ @override
bool get isStatic => true;
@override
@@ -2588,6 +2607,11 @@ class FieldElementForLink_EnumField extends FieldElementForLink
unlinkedEnumValue == null ? 'values' : unlinkedEnumValue.name;
@override
+ DartType get type => unlinkedEnumValue == null
+ ? enclosingElement.valuesType
+ : enclosingElement.type;
+
+ @override
noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation);
@override
@@ -3675,6 +3699,92 @@ abstract class PropertyAccessorElementForLink
}
/**
+ * Specialization of [PropertyAccessorElementForLink] for synthetic accessors
+ * implied by the synthetic fields of an enum declaration.
+ */
+class PropertyAccessorElementForLink_EnumField
+ implements PropertyAccessorElementForLink {
+ @override
+ final FieldElementForLink_EnumField variable;
+
+ FunctionTypeImpl _type;
+
+ PropertyAccessorElementForLink_EnumField(this.variable);
+
+ @override
+ ConstructorElementForLink get asConstructor => null;
+
+ @override
+ ConstVariableNode get asConstVariable => null;
+
+ @override
+ DartType get asStaticType => returnType;
+
+ @override
+ TypeInferenceNode get asTypeInferenceNode => null;
+
+ @override
+ Element get enclosingElement => variable.enclosingElement;
+
+ @override
+ bool get isGetter => true;
+
+ @override
+ bool get isSetter => false;
+
+ @override
+ bool get isStatic => variable.isStatic;
+
+ @override
+ bool get isSynthetic => true;
+
+ @override
+ ElementKind get kind => ElementKind.GETTER;
+
+ @override
+ LibraryElementForLink get library =>
+ variable.enclosingElement.enclosingElement.enclosingElement;
+
+ @override
+ String get name => variable.name;
+
+ @override
+ List<ParameterElement> get parameters => const [];
+
+ @override
+ DartType get returnType => variable.type;
+
+ @override
+ FunctionTypeImpl get type => _type ??= new FunctionTypeImpl(this);
+
+ @override
+ List<TypeParameterElement> get typeParameters => const [];
+
+ @override
+ DartType buildType(DartType getTypeArgument(int i),
+ List<int> implicitFunctionTypeIndices) =>
+ DynamicTypeImpl.instance;
+
+ @override
+ ReferenceableElementForLink getContainedName(String name) {
+ return new NonstaticMemberElementForLink(library, this, name);
+ }
+
+ @override
+ bool isAccessibleIn(LibraryElement library) =>
+ !Identifier.isPrivateName(name) || identical(this.library, library);
+
+ @override
+ void link(CompilationUnitElementInBuildUnit compilationUnit) {}
+
+ @override
+ noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation);
+
+ @override
+ String toString() => '$enclosingElement.$name';
+}
+
+/**
* Specialization of [PropertyAccessorElementForLink] for non-synthetic
* accessors explicitly declared in the source code.
*/
« no previous file with comments | « no previous file | pkg/analyzer/test/src/task/strong/inferred_type_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698