You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Jason Garrett (Jira)" <ji...@apache.org> on 2023/04/07 21:03:00 UTC
[jira] [Created] (GROOVY-11005) CompileStatic: Cannot set default-visible property in superclass that has a getter without a setter
Jason Garrett created GROOVY-11005:
--------------------------------------
Summary: CompileStatic: Cannot set default-visible property in superclass that has a getter without a setter
Key: GROOVY-11005
URL: https://issues.apache.org/jira/browse/GROOVY-11005
Project: Groovy
Issue Type: Bug
Components: Compiler
Affects Versions: 3.0.17
Reporter: Jason Garrett
If a class's ancestors declare a default-visibility property and a getter for that property:
{code:java}
class HasProperty {
Object foo
Object getFoo() {
return foo
}
} {code}
Then the class, if it is CompileStatic, cannot set that property.
This fails to compile:
{code:java}
import groovy.transform.CompileStatic
@CompileStatic
class SetsProperty extends HasProperty {
void doStuff() {
foo = "example"
}
} {code}
Compiler output:
{noformat}
SetsProperty.groovy: 8: [Static type checking] - Cannot set read-only property: foo
@ line 8, column 3.
foo = "example"{noformat}
It also fails to compile with "this.@":
{code:java}
import groovy.transform.CompileStatic
@CompileStatic
class SetsProperty extends HasProperty {
void doStuff() {
this.@foo = "example"
}
} {code}
Results in:
{noformat}
SetsProperty.groovy: 8: [Static type checking] - The field HasProperty.foo is not accessible
@ line 8, column 9.
this.@foo = "example"{noformat}
{{These do compile if the class is not CompileStatic, or if the property is explicitly declared "public".}}
--
This message was sent by Atlassian Jira
(v8.20.10#820010)