[
https://issues.apache.org/jira/browse/GROOVY-10100?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17349462#comment-17349462
]
Paul King edited comment on GROOVY-10100 at 4/27/22 8:53 AM:
-------------------------------------------------------------
See also GROOVY-9813. I don't think method reference to variadic method is
fully implemented.
was (Author: emilles):
See GROOVY-9813. I don't think method reference to variadic method is fully
implemented.
> 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
>
> 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)