You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Paul King (Jira)" <ji...@apache.org> on 2020/01/27 10:58:00 UTC

[jira] [Updated] (GROOVY-5490) Double Dispatch Distance Algorithm Incorrectly Implemented

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

Paul King updated GROOVY-5490:
------------------------------
    Fix Version/s:     (was: 3.x)
                   4.x

> Double Dispatch Distance Algorithm Incorrectly Implemented
> ----------------------------------------------------------
>
>                 Key: GROOVY-5490
>                 URL: https://issues.apache.org/jira/browse/GROOVY-5490
>             Project: Groovy
>          Issue Type: Bug
>          Components: groovy-runtime
>    Affects Versions: 1.8.4, 2.4.3
>            Reporter: thurston n
>            Priority: Major
>             Fix For: 4.x
>
>
> The following script 
> {code:borderStyle=solid}
>    1.  static foo(Object o, Integer i) { "Integer won" }
> 2.  static foo(String s, Object o) { "String won" }
> assert foo("potato", new Integer(6)) =~ "Integer"
> {code}
> fails.
> According to J. Theodorou, method resolution in Groovy employs a minimum _distance_ algorithm in determining which concrete method to invoke at runtime.
> The _distance_ of a single method parameter being computed as:
> distance(Class runtime, Class declaredParameter) ==> difference in level in inheritance tree, e.g. distance(String, Object) == 1 - 0 == 1, etc.
> therefore the total distance is just distance(param1) + distance(param2) + ...
> In the sample code above, the runtime distance of foo #1 would be (distance(String, Object) + distance(Integer, Integer)) == 1 + 0 == 1
> while distance of foo #2 would be (distance(String, String) + distance(Integer, Object)) == 0 + 2 == 2 (since Integer -> Number -> Object)
> Therefore foo #1 should have been selected
>  



--
This message was sent by Atlassian Jira
(v8.3.4#803005)