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

Scott Murphy Heiberg updated GROOVY-12521:
------------------------------------------
    Description: 
When the superclass declares several setters for a property, for example 
{{setX(int)}} and {{setX(String)}}, and the class overrides one of them or 
declares the property itself, {{super.x = value}} in dynamic Groovy and under 
{{@TypeChecked}} calls the class's own setter:

{code:groovy}
class Base {
    List<String> log = []
    String getX() { 'x:base' }
    void setX(int i) { log << 'base:int:' + i }
    void setX(String s) { log << 'base:string:' + s }
}
class Sub extends Base {
    String x = 'x:sub'
    List<String> test() {
        super.x = 'a'
        super.x = 1
        log + [x]
    }
}
assert new Sub().test() == ['base:string:a', 'base:int:1', 'x:sub'] // fails: 
[base:int:1, a]
{code}

{{super.x = 'a'}} called {{Sub.setX(String)}}, the setter of {{Sub}}'s own 
property. The same happens inside a closure. {{super.setX('a')}} calls 
{{Base.setX(String)}}, and so does {{super.x = 'a'}} under {{@CompileStatic}} 
or when {{Base}} has a single setter. Seen in 4.0.33, 5.0.8, 6.0.0 and master.

For {{super}}, a property with several setters is a {{MultipleSetterProperty}}, 
and its {{setProperty}} calls the setter by name with ordinary dispatch.

Expected: {{super.x = value}} chooses among the setters of the superclass, like 
{{super.setX(value)}}.

PR: https://github.com/apache/groovy/pull/3047 (split out of 
https://github.com/apache/groovy/pull/3044)

  was:
When the superclass declares several setters for a property, for example 
{{setX(int)}} and {{setX(String)}}, and the class overrides one of them or 
declares the property itself, {{super.x = value}} in dynamic Groovy and under 
{{@TypeChecked}} calls the class's own setter:

{code:groovy}
class Base {
    List<String> log = []
    String getX() { 'x:base' }
    void setX(int i) { log << 'base:int:' + i }
    void setX(String s) { log << 'base:string:' + s }
}
class Sub extends Base {
    String x = 'x:sub'
    List<String> test() {
        super.x = 'a'
        super.x = 1
        log + [x]
    }
}
assert new Sub().test() == ['base:string:a', 'base:int:1', 'x:sub'] // fails: 
[base:int:1, a]
{code}

{{super.x = 'a'}} called {{Sub.setX(String)}}, the setter of {{Sub}}'s own 
property. The same happens inside a closure. {{super.setX('a')}} calls 
{{Base.setX(String)}}, and so does {{super.x = 'a'}} under {{@CompileStatic}} 
or when {{Base}} has a single setter. Seen in 4.0.33, 5.0.8, 6.0.0 and master.

For {{super}}, a property with several setters is a {{MultipleSetterProperty}}, 
and its {{setProperty}} calls the setter by name with ordinary dispatch.

Expected: {{super.x = value}} chooses among the setters of the superclass, like 
{{super.setX(value)}}.

PR: https://github.com/apache/groovy/pull/3044


> super.x = value calls the class's own setter when the superclass overloads 
> the setter
> -------------------------------------------------------------------------------------
>
>                 Key: GROOVY-12521
>                 URL: https://issues.apache.org/jira/browse/GROOVY-12521
>             Project: Groovy
>          Issue Type: Bug
>          Components: groovy-runtime
>    Affects Versions: 6.0.0
>            Reporter: Scott Murphy Heiberg
>            Priority: Major
>
> When the superclass declares several setters for a property, for example 
> {{setX(int)}} and {{setX(String)}}, and the class overrides one of them or 
> declares the property itself, {{super.x = value}} in dynamic Groovy and under 
> {{@TypeChecked}} calls the class's own setter:
> {code:groovy}
> class Base {
>     List<String> log = []
>     String getX() { 'x:base' }
>     void setX(int i) { log << 'base:int:' + i }
>     void setX(String s) { log << 'base:string:' + s }
> }
> class Sub extends Base {
>     String x = 'x:sub'
>     List<String> test() {
>         super.x = 'a'
>         super.x = 1
>         log + [x]
>     }
> }
> assert new Sub().test() == ['base:string:a', 'base:int:1', 'x:sub'] // fails: 
> [base:int:1, a]
> {code}
> {{super.x = 'a'}} called {{Sub.setX(String)}}, the setter of {{Sub}}'s own 
> property. The same happens inside a closure. {{super.setX('a')}} calls 
> {{Base.setX(String)}}, and so does {{super.x = 'a'}} under {{@CompileStatic}} 
> or when {{Base}} has a single setter. Seen in 4.0.33, 5.0.8, 6.0.0 and master.
> For {{super}}, a property with several setters is a 
> {{MultipleSetterProperty}}, and its {{setProperty}} calls the setter by name 
> with ordinary dispatch.
> Expected: {{super.x = value}} chooses among the setters of the superclass, 
> like {{super.setX(value)}}.
> PR: https://github.com/apache/groovy/pull/3047 (split out of 
> https://github.com/apache/groovy/pull/3044)



--
This message was sent by Atlassian Jira
(v10.3.26#10030026)

Reply via email to