[ 
https://issues.apache.org/jira/browse/GROOVY-11029?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Jason Garrett updated GROOVY-11029:
-----------------------------------
    Description: 
If a class defines a default-visibility property and a subclass declares a 
getter and a setter for that property, the subclass cannot access super's 
property.
{code:java}
import groovy.transform.CompileStatic
import spock.lang.Specification

class Foo {
    Object myThing
}

@CompileStatic  // everything works without CompileStatic
class Bar extends Foo {
    void setMyThing(Object list) {
        super.myThing = list
    }
    
    Object getMyThing() {
        return super.myThing as List  // groovy.lang.MissingPropertyException: 
No such property: myThing for class: Bar
//        return super.@myThing as List  // [Static type checking] - The field 
Foo.myThing is not accessible
    }
}

class BarTest extends Specification {
    def "myThing"() {
        when:
            Bar bar = new Bar()
            List list = []
            bar.myThing = list
        then:
            bar.myThing.is(list)
    }
}{code}
[Live 
Demo|https://gwc-experiment.appspot.com/?g=groovy_4_0&codez=eJxtUUFuwjAQPNevWHGCQ8M9EhJq1Z5KWwluiENwNolLYlv2Qogq_l7bGEgKK9mSM5OZ3VnRaGUISqPUoUvIZNIWyjTJq2q0qHFJGQnOxJllteK7pM5kmSw1clEI7mAlGeN1Zi28KwW_DFx9bX-QEzTdqhKyZCfG5gNFgOkU8ICmI0-AVpmdhVZQpfYEQ_Oz9ktmAI-EMu_7HJTIwSItzkbj6FsLS5NI8WX3Gk0Su4FZwAN4Cne_5fIm1lcwSHsj_wllFj6cUhgmJhjCWQhrHf5tlGNT93bkqH1OKXwqJ8Er0BFKLxGBSx3CpKkflTnFR87zR9brmCl1GoFXyHeOsYFnWFUIhcA694lduxYWpCLIOEfX5rbGmMSJ3aJeodO-xD3YdcwkxwJGUXE0SKqtUKbXly-_uq07M5DY-td4csWfwhR-Hw5eb27f3Q-PFuaL7hx65ETYcVj_Zao_zwXo-w]

A workaround is to declare a getter and setter in the superclass.

  was:
If a class defines a default-visibility property and a subclass declares a 
getter and a setter for that property, the subclass cannot access super's 
property.
{code:java}
import groovy.transform.CompileStatic
import spock.lang.Specification

class Foo {
    Object myThing
}

@CompileStatic  // everything works without CompileStatic
class Bar extends Foo {
    void setMyThing(Object list) {
        super.myThing = list
    }
    
    Object getMyThing() {
        return super.myThing as List  // groovy.lang.MissingPropertyException: 
No such property: myThing for class: Bar
//        return super.@myThing as List  // [Static type checking] - The field 
Foo.myThing is not accessible
    }
}

class BarTest extends Specification {
    def "myThing"() {
        when:
            Bar bar = new Bar()
            List list = []
            bar.myThing = list
        then:
            bar.myThing.is(list)
    }
}{code}
[Live 
Demo|https://gwc-experiment.appspot.com/?g=groovy_4_0&codez=eJxtUUFuwjAQPNevWHGCQ8M9EhJq1Z5KWwluiENwNolLYlv2Qogq_l7bGEgKK9mSM5OZ3VnRaGUISqPUoUvIZNIWyjTJq2q0qHFJGQnOxJllteK7pM5kmSw1clEI7mAlGeN1Zi28KwW_DFx9bX-QEzTdqhKyZCfG5gNFgOkU8ICmI0-AVpmdhVZQpfYEQ_Oz9ktmAI-EMu_7HJTIwSItzkbj6FsLS5NI8WX3Gk0Su4FZwAN4Cne_5fIm1lcwSHsj_wllFj6cUhgmJhjCWQhrHf5tlGNT93bkqH1OKXwqJ8Er0BFKLxGBSx3CpKkflTnFR87zR9brmCl1GoFXyHeOsYFnWFUIhcA694lduxYWpCLIOEfX5rbGmMSJ3aJeodO-xD3YdcwkxwJGUXE0SKqtUKbXly-_uq07M5DY-td4csWfwhR-Hw5eb27f3Q-PFuaL7hx65ETYcVj_Zao_zwXo-w]


> CompileStatic: default-visible property is not accessible by a subclass that 
> defines a getter and setter
> --------------------------------------------------------------------------------------------------------
>
>                 Key: GROOVY-11029
>                 URL: https://issues.apache.org/jira/browse/GROOVY-11029
>             Project: Groovy
>          Issue Type: Bug
>          Components: Compiler, Static compilation
>    Affects Versions: 4.0.11
>            Reporter: Jason Garrett
>            Priority: Major
>
> If a class defines a default-visibility property and a subclass declares a 
> getter and a setter for that property, the subclass cannot access super's 
> property.
> {code:java}
> import groovy.transform.CompileStatic
> import spock.lang.Specification
> class Foo {
>     Object myThing
> }
> @CompileStatic  // everything works without CompileStatic
> class Bar extends Foo {
>     void setMyThing(Object list) {
>         super.myThing = list
>     }
>     
>     Object getMyThing() {
>         return super.myThing as List  // 
> groovy.lang.MissingPropertyException: No such property: myThing for class: Bar
> //        return super.@myThing as List  // [Static type checking] - The 
> field Foo.myThing is not accessible
>     }
> }
> class BarTest extends Specification {
>     def "myThing"() {
>         when:
>             Bar bar = new Bar()
>             List list = []
>             bar.myThing = list
>         then:
>             bar.myThing.is(list)
>     }
> }{code}
> [Live 
> Demo|https://gwc-experiment.appspot.com/?g=groovy_4_0&codez=eJxtUUFuwjAQPNevWHGCQ8M9EhJq1Z5KWwluiENwNolLYlv2Qogq_l7bGEgKK9mSM5OZ3VnRaGUISqPUoUvIZNIWyjTJq2q0qHFJGQnOxJllteK7pM5kmSw1clEI7mAlGeN1Zi28KwW_DFx9bX-QEzTdqhKyZCfG5gNFgOkU8ICmI0-AVpmdhVZQpfYEQ_Oz9ktmAI-EMu_7HJTIwSItzkbj6FsLS5NI8WX3Gk0Su4FZwAN4Cne_5fIm1lcwSHsj_wllFj6cUhgmJhjCWQhrHf5tlGNT93bkqH1OKXwqJ8Er0BFKLxGBSx3CpKkflTnFR87zR9brmCl1GoFXyHeOsYFnWFUIhcA694lduxYWpCLIOEfX5rbGmMSJ3aJeodO-xD3YdcwkxwJGUXE0SKqtUKbXly-_uq07M5DY-td4csWfwhR-Hw5eb27f3Q-PFuaL7hx65ETYcVj_Zao_zwXo-w]
> A workaround is to declare a getter and setter in the superclass.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to