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

Jochen Theodorou resolved GROOVY-7655.
--------------------------------------
       Resolution: Fixed
         Assignee: Jochen Theodorou
    Fix Version/s: 2.5.0-beta-1
                   2.4.8

after thinking about how to solve the issue for a bit it was actually quite 
easy to find a solution. The compiler will now ensure, that methods used with 
super will find their mop helper method. This happens regardless of the 
signature, so there are still useless methods generated, but still many less 
than in 2.3

> Wrong method is chosen when using super with generics
> -----------------------------------------------------
>
>                 Key: GROOVY-7655
>                 URL: https://issues.apache.org/jira/browse/GROOVY-7655
>             Project: Groovy
>          Issue Type: Bug
>    Affects Versions: 2.4.4
>            Reporter: Marius Vaitkus
>            Assignee: Jochen Theodorou
>             Fix For: 2.4.8, 2.5.0-beta-1
>
>         Attachments: generics_extension_test.groovy
>
>
> Given code:
> {code:title=generics_extension_test.groovy}
> interface ParamInterface{}
> class ParamImplementation implements ParamInterface{}
> class ParamExtension extends ParamImplementation {}
> class A<T extends ParamInterface> {
>     def getResult(T a) {
>         return "A"
>     }
> }
> class B<T extends ParamImplementation> extends A<T> {
>     def getResult(T b) {
>         return "B"
>     }
> }
> class C extends B<ParamExtension> {
>     @Override
>     def getResult(ParamExtension b) {
>         return super.getResult(b)
>     }
> }
> String result = new C().getResult(new ParamExtension())
> assert result == "B"
> {code}
> I get output:
> {code}
> Assertion failed: 
> assert result == "B"
>        |      |
>        A      false
>       at generics_extension_test.run(generics_extension_test.groovy:31)
> {code}
> When calling super method, instead of looking for method in a class one 
> hierarchy bellow, groovy goes through complex calculations for finding a 
> better method. I debug'ed up to a point in 
> groovy.lang.MetaClassImpl#chooseMostSpecificParams
> where it turned out that distance for interface was 2 and distance for class 
> that directly extends the method was much bigger, therefore the method from 
> class A is chosen instead of method from class B. However, looking 
> objectively, it would seem that B.getResult is a much better fit:
> C extends B and B extends A
> parameter hierarchy is shorter (ParamExtension -> ParamImplementation -> 
> ParamInterface)



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to