Description
If a class's ancestors declare a default-visibility property and a getter for that property:
class HasProperty { Object foo Object getFoo() { return foo } }
Then the class, if it is CompileStatic, cannot set that property.
This fails to compile:
import groovy.transform.CompileStatic @CompileStatic class SetsProperty extends HasProperty { void doStuff() { foo = "example" } }
Compiler output:
SetsProperty.groovy: 8: [Static type checking] - Cannot set read-only property: foo @ line 8, column 3. foo = "example"
It also fails to compile with "this.@":
import groovy.transform.CompileStatic @CompileStatic class SetsProperty extends HasProperty { void doStuff() { this.@foo = "example" } }
Results in:
SetsProperty.groovy: 8: [Static type checking] - The field HasProperty.foo is not accessible @ line 8, column 9. this.@foo = "example"
These do compile if the class is not CompileStatic, or if the property is explicitly declared "public".
Attachments
Issue Links
- is related to
-
GROOVY-9127 Cannot set protected field from subclass
- Closed
-
GROOVY-5450 Final field assignment check on static compilation
- Closed