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:04:00 UTC
[jira] [Updated] (GROOVY-11005) CompileStatic: Cannot set default-visible property in superclass that has a getter without a setter
[ https://issues.apache.org/jira/browse/GROOVY-11005?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Jason Garrett updated GROOVY-11005:
-----------------------------------
Description:
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".}}
was:
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".}}
> 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
> Priority: Minor
>
> 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)