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 2022/04/27 08:58:00 UTC
[jira] [Closed] (GROOVY-10100) groovyc infers the wrong type when using a method reference of a function with varargs
[ https://issues.apache.org/jira/browse/GROOVY-10100?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Paul King closed GROOVY-10100.
------------------------------
Unsure of the exact fix version but works on 4.0.2.
> groovyc infers the wrong type when using a method reference of a function with varargs
> --------------------------------------------------------------------------------------
>
> Key: GROOVY-10100
> URL: https://issues.apache.org/jira/browse/GROOVY-10100
> Project: Groovy
> Issue Type: Bug
> Components: Static Type Checker
> Reporter: Thodoris Sotiropoulos
> Assignee: Eric Milles
> Priority: Major
> Labels: varargs
> Fix For: 4.0.2
>
>
> I have the following program
>
> {code:java}
> import java.util.function.Function;
> class Foo<T> {
> public T method(Object... args) {
> return null;
> }
> }
> class Bar {
> public static <T extends Number> void test(T a) {
> Foo<T> x = new Foo<>();
> Function<String[], T> b = x::method;
> T y = b.apply(new String[] {"str"});
> }
> }
> public class Main {
> public static void main(String[] args) {
> Bar.test(1);
> }
> }
> {code}
> h3. Actual Behaviour
> {code:java}
> org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
> groovy4.groovy: 14: [Static type checking] - Cannot assign value of type java.lang.String[] to variable of type T
> @ line 14, column 15.
> T y = b.apply(new String[] {"str"});
> ^1 error
> {code}
> h3. Expected Behaviour
> Compile successfully
>
> Note that if I remove the `extends` from the parameterized function, the code compiles as expected.
>
> Tested against master https://github.com/apache/groovy/commit/9961a67db31f7889cfb9a927ccc26c3ece0e41b9
>
--
This message was sent by Atlassian Jira
(v8.20.7#820007)