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 2021/03/02 15:16:00 UTC

[jira] [Resolved] (GROOVY-9881) STC can't distinguish SAMs based on arity

     [ https://issues.apache.org/jira/browse/GROOVY-9881?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Eric Milles resolved GROOVY-9881.
---------------------------------
    Fix Version/s: 4.0.0-alpha-3
       Resolution: Fixed

> 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.3.4#803005)