Initializers prohibited on val-properties with no backing field

This commit is contained in:
Andrey Breslav
2011-04-22 14:23:58 +04:00
parent bbf4fbc34f
commit 55518cd654
2 changed files with 8 additions and 1 deletions
@@ -392,6 +392,10 @@ public class TopDownAnalyzer {
if (setter != null && setterDescriptor != null) {
resolveFunctionBody(fieldAccessTrackingTrace, setter, setterDescriptor, accessorScope);
}
if (!declaration.isVar() && initializer != null && !trace.hasBackingField(propertyDescriptor)) {
semanticServices.getErrorHandler().genericError(initializer.getNode(), "Initializer is not allowed here because this property has no setter and no backing field either");
}
}
}
+4 -1
View File
@@ -5,10 +5,13 @@
$x = <error>1.lng</error>
}
val xx : Int = 1 + x
val xx : Int = <error>1 + x</error>
get() : Int = 1
<error>set(ref value : Long) {$x = value}</error>
val p : Int = <error>1</error>
get() = 1
class Test {
var a : Int
var b : Int get() = <error>$a</error>; set(x) {a = x; <error>$a</error> = x}