Scott Murphy Heiberg created GROOVY-12521:
---------------------------------------------

             Summary: 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


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)}}.



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

Reply via email to