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/04/18 20:11:00 UTC
[jira] [Commented] (GROOVY-11009) STC resolves wrong method reference
[ https://issues.apache.org/jira/browse/GROOVY-11009?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17713750#comment-17713750 ]
Eric Milles commented on GROOVY-11009:
--------------------------------------
The method reference has 2 methods that may satisfy:
# the static method declared by Main
# the instance method declared by Object
STC does not remove #2 from the candidate list and then subsequent parameter and return type checks aren't strictly limited to the type parameter "T".
> STC resolves wrong method reference
> -----------------------------------
>
> Key: GROOVY-11009
> URL: https://issues.apache.org/jira/browse/GROOVY-11009
> Project: Groovy
> Issue Type: Bug
> Components: Static Type Checker
> Reporter: Thodoris Sotiropoulos
> Assignee: Eric Milles
> Priority: Minor
>
> This is probably a regression
> I have the following program
> {code}
> import java.util.function.*;
> class Main {
> static final void test() {
> final Function<Double, Double> x = Main::clone;
> }
> public static <T> T clone(T x) { return x; }
> }
> {code}
> h3. Actual behavior
> {code}
> org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
> test.groovy: 5: [Static type checking] - Invalid return type: java.lang.Object is not convertible to java.lang.Double
> @ line 5, column 40.
> final Function<Double, Double> x = Main::clone;
> ^
> 1 error
> {code}
> h3. Expected behavior
> Compile successfully
> h3. Notes
> Tested against master (commit: c4ee3ce0661eec7d633fc81281d79c8889b3dc66)
> Test case adapted from:
> {code}
> import java.util.function.*;
> class Main {
> static final void test() {
> Function<Double, Double> x = org.apache.commons.lang3.ObjectUtils::clone;
> }
> }
> {code}
--
This message was sent by Atlassian Jira
(v8.20.10#820010)