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

Unified Diff: compiler/java/com/google/dart/compiler/type/TypeAnalyzer.java

Issue 12039056: Issue 7597. Use foo= when setter requested, even if there is method foo(). (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 11 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 | compiler/javatests/com/google/dart/compiler/type/TypeAnalyzerCompilerTest.java » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: compiler/java/com/google/dart/compiler/type/TypeAnalyzer.java
diff --git a/compiler/java/com/google/dart/compiler/type/TypeAnalyzer.java b/compiler/java/com/google/dart/compiler/type/TypeAnalyzer.java
index b1a6d91a56c9d9eddd7a0467aa4acb40baa25aff..cd9238ec31dfa7962c2a750d0bd4a9ba905685e9 100644
--- a/compiler/java/com/google/dart/compiler/type/TypeAnalyzer.java
+++ b/compiler/java/com/google/dart/compiler/type/TypeAnalyzer.java
@@ -2383,11 +2383,16 @@ public class TypeAnalyzer implements DartCompilationPhase {
}
// Do not visit the name, it may not have been resolved.
String name = node.getPropertyName();
- InterfaceType.Member member = cls.lookupMember(name);
- if (member == null || ASTNodes.inSetterContext(node)) {
- InterfaceType.Member member2 = cls.lookupMember("setter " + name);
- if (member2 != null && (member == null || member2.getHolder() == member.getHolder() || types.isSubtype(member2.getHolder(), member.getHolder()))) {
- member = member2;
+ InterfaceType.Member member;
+ if (ASTNodes.inSetterContext(node)) {
+ member = cls.lookupMember("setter " + name);
+ if (member == null) {
+ member = cls.lookupMember(name);
+ }
+ } else {
+ member = cls.lookupMember(name);
+ if (member == null) {
+ member = cls.lookupMember("setter " + name);
}
}
// is "receiver" is inferred, attempt to find member in one of the subtypes
@@ -2436,55 +2441,40 @@ public class TypeAnalyzer implements DartCompilationPhase {
case FIELD:
FieldElement fieldElement = (FieldElement) element;
Modifiers fieldModifiers = fieldElement.getModifiers();
- MethodElement getter = fieldElement.getGetter();
- MethodElement setter = fieldElement.getSetter();
+
+ // Prepare getter/setter members.
+ Member getterMember;
+ Member setterMember;
+ {
+ getterMember = cls.lookupMember(name);
+ if (getterMember == null && TypeQuality.of(cls) == TypeQuality.INFERRED) {
+ getterMember = cls.lookupSubTypeMember(name);
+ }
+ }
+ {
+ setterMember = cls.lookupMember("setter " + name);
+ if (setterMember == null) {
+ setterMember = cls.lookupMember(name);
+ }
+ }
boolean inSetterContext = ASTNodes.inSetterContext(node);
boolean inGetterContext = ASTNodes.inGetterContext(node);
- ClassElement enclosingClass = null;
- if (fieldElement.getEnclosingElement() instanceof ClassElement) {
- enclosingClass = (ClassElement) fieldElement.getEnclosingElement();
- }
// Implicit field declared as "final".
if (!fieldModifiers.isAbstractField() && fieldModifiers.isFinal() && inSetterContext) {
return typeError(node.getName(), TypeErrorCode.FIELD_IS_FINAL, node.getName());
}
- // Check for cases when property has no setter or getter.
- if (fieldModifiers.isAbstractField() && enclosingClass != null) {
- // Check for using field without setter in some assignment variant.
- if (inSetterContext) {
- if (setter == null) {
- setter = Elements.lookupFieldElementSetter(enclosingClass, name);
- if (setter == null) {
- setter = Elements.lookupFieldElementSetter(enclosingClass, "setter " + name);
- }
- if (setter == null) {
- return typeError(node.getName(), TypeErrorCode.FIELD_HAS_NO_SETTER, node.getName());
- }
- }
- }
- // Check for using field without getter in other operation that assignment.
- if (inGetterContext) {
- if (getter == null) {
- getter = Elements.lookupFieldElementGetter(enclosingClass, name);
- if (getter == null) {
- return typeError(node.getName(), TypeErrorCode.FIELD_HAS_NO_GETTER, node.getName());
- }
- }
- }
- }
-
Type result = member.getType();
if (fieldModifiers.isAbstractField()) {
if (inSetterContext) {
- result = member.getSetterType();
+ result = setterMember != null ? setterMember.getSetterType() : null;
if (result == null) {
return typeError(node.getName(), TypeErrorCode.FIELD_HAS_NO_SETTER, node.getName());
}
}
if (inGetterContext) {
- result = member.getGetterType();
+ result = getterMember != null ? getterMember.getGetterType() : null;
if (result == null) {
return typeError(node.getName(), TypeErrorCode.FIELD_HAS_NO_GETTER, node.getName());
}
« no previous file with comments | « no previous file | compiler/javatests/com/google/dart/compiler/type/TypeAnalyzerCompilerTest.java » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698