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

Eric Milles commented on GROOVY-11025:
--------------------------------------

Works if "K" is renamed in the test method, in case anyone is looking for a 
workaround.

> Conficts between type parameter names result in unexpected type error
> ---------------------------------------------------------------------
>
>                 Key: GROOVY-11025
>                 URL: https://issues.apache.org/jira/browse/GROOVY-11025
>             Project: Groovy
>          Issue Type: Bug
>          Components: Static Type Checker
>            Reporter: Thodoris Sotiropoulos
>            Priority: Minor
>
> I have the following program
> {code}
> import java.util.Map;
> import java.util.List;
> class Main {
>   static <K, V> void m(Map<K, V> map, K key, V value) {}
>   static final <K>void test() {
>     Map<List<K>, K> map = null;
>     List<K> key = null;
>     K value = null;
>     Main.m(map, key, value);
>   }
> }
> {code}
> h3. Actual behavior 
> {code}
> org.codehaus.groovy.control.MultipleCompilationErrorsException: startup 
> failed:
> test.groovy: 11: [Static type checking] - Cannot find matching method 
> Main#m(java.util.Map<java.util.List<K>, K>, java.util.List<K>, K). Please 
> check if the declared type is correct and if the method exists.
>  @ line 11, column 5.
>        Main.m(map, key, value);
>        ^
> {code}
> h3. Expected behavior
> Compile successfully
> h3. Notes
> Tested against master (commit: 8346e3406ed51dd071a2d31792d3fbad543585a7)
> The error is triggered only when instantiating method m with a type variable 
> of the same name as its first type parameter.
> Test case adapted from the following program that uses the 
> apache-commons-lang3 lib:
> {code}
> import java.util.List;
> import java.util.concurrent.ConcurrentMap;
> import org.apache.commons.lang3.concurrent.ConcurrentInitializer;
> import org.apache.commons.lang3.concurrent.ConcurrentUtils;
> class Main {
>   static final <K>void test() {
>     ConcurrentMap<List<K>, K> map = null;
>     List<K> key = null;
>     ConcurrentInitializer<K> init = null;
>     ConcurrentUtils.<List<K>, K>createIfAbsentUnchecked(map, key, init);
>   }
> }
> {code}



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

Reply via email to