Details
-
Bug
-
Status: Closed
-
Major
-
Resolution: Fixed
-
3.0.7
-
None
Description
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.
@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)) } } }
Attachments
Issue Links
- relates to
-
GROOVY-11010 Ambiguous method reference when expecting a SAM type
- Open
-
GROOVY-10714 STC: Callable, Runnable, Serializable overload preference for functional argument (closure, lambda, etc.)
- Reopened
-
GROOVY-10963 AIOOBE with Java lambda syntax
- Closed
-
GROOVY-11121 unexpected error when having overloaded methods, one of which receiving an Iterable
- Closed