You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Eric Milles (Jira)" <ji...@apache.org> on 2023/04/28 16:48:00 UTC

[jira] [Resolved] (GROOVY-11029) SC: super property is not accessible by a subclass that defines a getter and setter

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

Eric Milles resolved GROOVY-11029.
----------------------------------
    Resolution: Fixed

https://github.com/apache/groovy/commit/707ed5a0e85b6182df44894419c32fb6600687f1

NOTE: if a type-checking extension clears direct target for {{super.m()}} or {{super.p}}, it may be necessary to generate a MOP method; this can be done with:
{code:java}
    if (isSuperExpression(expression.getObjectExpression())) {
        ClassNode superCaller =
typeCheckingContext.getEnclosingClassNode();
        superCaller.getNodeMetaData(SUPER_MOP_METHOD_REQUIRED, x -> new
LinkedList<>()).add(methodTarget);
    }
{code}

> SC: super 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
>            Assignee: Eric Milles
>            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)