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/06/11 19:12:00 UTC

[jira] [Commented] (GROOVY-11042) Wrong method is chosen from the Groovy runtime

    [ https://issues.apache.org/jira/browse/GROOVY-11042?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17731392#comment-17731392 ] 

Eric Milles commented on GROOVY-11042:
--------------------------------------

{{TreeMap#subMap(K,K)}} scores 536 and DGM {{Map#subMap(K[])}} scores 523 in the distance calculation.  We could increase the varargs penalty in {{StaticTypeCheckingSupport#getVarargsDistance}} as one possible solution.

I think this is an edge case that very few users would come across.  Arrays are not comparable and only support identity equals so their use as a map key type is questionable.  I'd like to see a real use case before making any changes to the method distance algorithm.

> Wrong method is chosen from the Groovy runtime
> ----------------------------------------------
>
>                 Key: GROOVY-11042
>                 URL: https://issues.apache.org/jira/browse/GROOVY-11042
>             Project: Groovy
>          Issue Type: Bug
>          Components: Static Type Checker
>            Reporter: Thodoris Sotiropoulos
>            Assignee: Eric Milles
>            Priority: Minor
>
> I have the following code
> {code}
> class Main {
>   static final void test() {
>     String[] p1 = new String[]{"v2"};
>     String[] p2 = new String[]{"v1"};
>     java.util.TreeMap<String[], Number> x = null;
>     x.subMap(p1, p2);
>   }
> }
> {code}
> h3. Actual behavior
> {code}
> org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
> test.groovy: 6: [Static type checking] - Cannot call <K,V> org.codehaus.groovy.runtime.DefaultGroovyMethods#subMap(java.util.Map<K, V>, K[]) with arguments [java.util.TreeMap<java.lang.String[], java.lang.Number>, java.lang.String[], java.lang.String[]]
>  @ line 6, column 5.
>        x.subMap(p1, p2);
>        ^
> 1 error
> {code}
> h3. Expected behavior
> Compile successfully
> h3. Notes
> Tested against master (commit: ce357be7e43542480a8e01f383aac69b19e1fe8f)
> Perhaps, an incorrect method is chosen (see https://docs.groovy-lang.org/latest/html/api/org/codehaus/groovy/runtime/DefaultGroovyMethods.html#subMap(java.util.Map,K%5B%5D)) instead of https://docs.oracle.com/en/java/javase/12/docs/api/java.base/java/util/TreeMap.html#subMap(K,K).



--
This message was sent by Atlassian Jira
(v8.20.10#820010)