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

Eric Milles edited comment on GROOVY-11010 at 1/15/24 1:44 PM:
---------------------------------------------------------------

Replacing “Main::m” with “(String s) -> Main.m(s)” should allow disambiguation 
by param count (see GROOVY-9881).

GROOVY-10714 seeks to apply the same for method pointer/reference. A change in 
the order of steps caused a regression here for Groovy 5.


was (Author: emilles):
Replacing “Main::m” with “s -> Main.m(s)” should allow disambiguation by param 
count (see GROOVY-9881).

GROOVY-10714 seeks to apply the same for method pointer/reference. A change in 
the order of steps caused a regression here for Groovy 5. 

> Ambiguous method reference when expecting a SAM type
> ----------------------------------------------------
>
>                 Key: GROOVY-11010
>                 URL: https://issues.apache.org/jira/browse/GROOVY-11010
>             Project: Groovy
>          Issue Type: Bug
>          Components: Static Type Checker
>            Reporter: Thodoris Sotiropoulos
>            Assignee: Eric Milles
>            Priority: Minor
>
> I have the following program
> {code}
> import java.util.function.*;
> class Main {
>   static final void test() {
>     from(Main::m);
>   }
>   static <K, V> void from(Function<K, V> f) {}
>   static <V> void from(Supplier<V> f) {}
>   static int m(String x) { return 1; }
> }
> {code}
> h3. Actual behavior
> {code}
> org.codehaus.groovy.control.MultipleCompilationErrorsException: startup 
> failed:
> test.groovy: 6: [Static type checking] - Reference to method is ambiguous. 
> Cannot choose between [void Main#from(java.util.function.Supplier<V>), void 
> Main#from(java.util.function.Function<K, V>)]
>  @ line 6, column 5.
>        from(Main::m);
>        ^
> 1 error
> {code}
> h3. Expected behavior 
> Compile successfully
> h3. Notes
> Tested against master (commit: 5bcd83e0fde722971f97d479f1a4d6da6cd4aa5f)
> Test case adapted from (Guava library)
> {code}
> import java.util.function.*;
> class Main {
>   static final void test() {
>     com.google.common.cache.CacheLoader.from(Main::m);
>   }
> }
> {code}



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

Reply via email to