[ https://issues.apache.org/jira/browse/GROOVY-8084?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17897281#comment-17897281 ]
ASF GitHub Bot commented on GROOVY-8084: ---------------------------------------- eric-milles opened a new pull request, #2121: URL: https://github.com/apache/groovy/pull/2121 When comparing method call arguments to parameters, wildcard generics are considered captured. Thus, they are not compatible with other types. https://docs.oracle.com/javase/tutorial/extra/generics/wildcards.html **TODO:** The test case for GROOVY-10006 / GROOVY-10339 produces a wildcard for `LowestUpperBoundClassNode` and so it fails ```groovy def <T> void test(T x, T y, T z) { } test(1,"II",Class) // Cannot call <T> test(T, T, T) with arguments [int, String, Class] ``` > Captured types doesn't work in @CompileStatic > --------------------------------------------- > > Key: GROOVY-8084 > URL: https://issues.apache.org/jira/browse/GROOVY-8084 > Project: Groovy > Issue Type: Bug > Components: Static compilation, Static Type Checker > Affects Versions: 2.4.8 > Reporter: Alexey Afanasiev > Assignee: Daniel Sun > Priority: Major > Fix For: 3.0.0-alpha-4, 2.5.3 > > > This code could be successfully compiled and executed. > {code} > @CompileStatic > static def method(List<? extends Serializable> captured) { > captured.add('some string') > return captured > } > println method(new ArrayList<Integer>()) > {code} > Looks like type check in groovy doesn't work with captured types. Is it a bug? > Is there any documentation about generics in groovy? > P.S.: > Another kind of strange behaviour: > {code} > @CompileStatic > static def method() { > List<Integer> list = new ArrayList<>() > List<? extends Serializable> captured = list > captured.add('some string') //Error:(7, 5) Groovyc: [Static type > checking] - Cannot call java.util.ArrayList > <java.lang.Integer>#add(java.lang.Integer) with arguments [java.lang.String] > return captured > } > {code} > Somehow type checking infered type of 'captured' variable to > java.util.ArrayList <java.lang.Integer> -- This message was sent by Atlassian Jira (v8.20.10#820010)