[
https://issues.apache.org/jira/browse/GROOVY-9881?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17697177#comment-17697177
]
Eric Milles commented on GROOVY-9881:
-------------------------------------
https://github.com/apache/groovy/commit/2ccf35441320f3ef473f6483b6ddc2cf5c731046
> STC can't distinguish SAMs based on arity
> -----------------------------------------
>
> Key: GROOVY-9881
> URL: https://issues.apache.org/jira/browse/GROOVY-9881
> Project: Groovy
> Issue Type: Bug
> Components: Static Type Checker
> Affects Versions: 3.0.7
> Reporter: Christopher Smith
> Assignee: Eric Milles
> Priority: Major
> Fix For: 4.0.0-alpha-3
>
> Time Spent: 50m
> Remaining Estimate: 0h
>
> I'm using Vavr, which has a number of methods with overloads that take
> alternately a Supplier or a Function (particularly for creating an exception
> instance). The STC can't disambiguate which overload to call, _even when the
> syntax is explicit_.
> In the below code, each call to {{replace}} is entirely unambiguous, but the
> compiler reports "Reference to method is ambiguous" on both. Of course, the
> problem persists with closures. Only wrapping the entire lambda (including
> {{()}}) in parens and using {{as Function}} (or Supplier) works.
> {code:groovy}
> @CompileStatic
> class Groovy9881 {
> def doReplace() {
> new Value(123)
> .replace(() -> "foo")
> new Value(123)
> .replace((Integer v) -> "bar")
> }
> static class Value<V> {
> final V val
> Value(V v) {
> this.val = v
> }
> <T> Value<T> replace(Supplier<T> supplier) {
> new Value<>(supplier.get())
> }
> <T> Value<T> replace(Function<? super V, ? extends T> function) {
> new Value(function.apply(val))
> }
> }
> }
> {code}
--
This message was sent by Atlassian Jira
(v8.20.10#820010)