$field is only allowed in property accessors

This commit is contained in:
Andrey Breslav
2011-04-20 16:25:35 +04:00
parent 9add2b6114
commit ca579e25b7
3 changed files with 21 additions and 3 deletions
@@ -244,7 +244,6 @@ public class TopDownAnalyzer {
declaringScopes.put(property, declaringScope);
PropertyDescriptor descriptor = classDescriptorResolver.resolvePropertyDescriptor(declaringScope.getContainingDeclaration(), declaringScope, property);
declaringScope.addVariableDescriptor(descriptor);
declaringScope.addPropertyDescriptorByFieldName("$" + descriptor.getName(), descriptor);
properties.put(property, descriptor);
}
@@ -302,6 +301,7 @@ public class TopDownAnalyzer {
if (expression instanceof JetSimpleNameExpression) {
JetSimpleNameExpression simpleNameExpression = (JetSimpleNameExpression) expression;
if (simpleNameExpression.getReferencedNameElementType() == JetTokens.FIELD_IDENTIFIER) {
// This check may be considered redundant as long as $x is only accessible from accessors to $x
if (descriptor == propertyDescriptor) { // TODO : original?
recordFieldAccessFromAccessor(propertyDescriptor);
}
@@ -310,16 +310,19 @@ public class TopDownAnalyzer {
}
};
WritableScope accessorScope = semanticServices.createWritableScope(declaringScope, declaringScope.getContainingDeclaration());
accessorScope.addPropertyDescriptorByFieldName("$" + propertyDescriptor.getName(), propertyDescriptor);
JetPropertyAccessor getter = declaration.getGetter();
PropertyGetterDescriptor getterDescriptor = propertyDescriptor.getGetter();
if (getter != null && getterDescriptor != null) {
resolveFunctionBody(fieldAccessTrackingTrace, getter, getterDescriptor, declaringScope);
resolveFunctionBody(fieldAccessTrackingTrace, getter, getterDescriptor, accessorScope);
}
JetPropertyAccessor setter = declaration.getSetter();
PropertySetterDescriptor setterDescriptor = propertyDescriptor.getSetter();
if (setter != null && setterDescriptor != null) {
resolveFunctionBody(fieldAccessTrackingTrace, setter, setterDescriptor, declaringScope);
resolveFunctionBody(fieldAccessTrackingTrace, setter, setterDescriptor, accessorScope);
}
}
}
+10
View File
@@ -8,3 +8,13 @@
val xx : Int = 1 + x
get() : Int = 1
<error>set(ref value : Long) {$x = value}</error>
class Test {
var a : Int
var b : Int get() = <error>$a</error>; set(x) {a = x; <error>$a</error> = x}
this() {
<error>$b</error> = <error>$a</error>
a = <error>$b</error>
}
}
@@ -15,6 +15,8 @@ class Test {
<info>get</info>() { return 1 }
val c4 : Int
<info>get</info>() { 1 }
val <info>c5</info> : Int
<info>get</info>() { $c5 + 1 }
<info>abstract</info> var y : Int
<info>abstract</info> var y1 : Int <info>get</info>
@@ -28,4 +30,7 @@ class Test {
var <info>v2</info> : Int <info>get</info> <info>set</info>
var <info>v3</info> : Int <info>get</info>() = 1; <info>set</info>
var v4 : Int <info>get</info>() = 1; <info>set</info>(x){}
var <info>v5</info> : Int <info>get</info>() = 1; <info>set</info>(x){$v5 = x}
var <info>v6</info> : Int <info>get</info>() = $v6 + 1; <info>set</info>(x){}
}