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

Paul King updated GROOVY-12759:
-------------------------------
    Description: 
This clone is for work done in Groovy 7: closure/lambda selection 76d6bfc5a9

Original issue appears below.

This appears to be similar to GROOVY-9881, but it's specifically in the 
method-overload procedure. Given a functional value type with two method 
overloads:

{code}
interface Try<T> {
  Try<T> andThenTry(Consumer<? super T>)
  Try<T> andThenTry(Runnable)
}
{code}

When this code is invoked from static code, the STC errors out on an ambiguous 
method reference even if the method type isn't:

{code}
// AWS SDK 2 DynamoDbTable
class DynamoDbTable {
  void putItem(PutItemRequest<T>)
  void putItem(Consumer<PutItemRequest.Builder<T>)
  void putItem(T)
}


@CompileStatic
class MyServiceClass {
  void doThing() {
    Try.success(putItemRequest())
      .andThenTry(table::putItem) // T for Try<T> is PutItemRequest<I>
  }
}
{code}

produces

{code}
[Static type checking] - Reference to method is ambiguous. Cannot choose 
between [Try<T> Try#andThenTry(Consumer<? super T>), Try<T> 
Try#andThenTry(Runnable)]
{code}

I think this may have something to do with the relaxed SAM matching that is 
used to bridge ambiguous closure syntax, but when a plain method reference is 
used, there's no ambiguity available.

  was:
This appears to be similar to GROOVY-9881, but it's specifically in the 
method-overload procedure. Given a functional value type with two method 
overloads:

{code}
interface Try<T> {
  Try<T> andThenTry(Consumer<? super T>)
  Try<T> andThenTry(Runnable)
}
{code}

When this code is invoked from static code, the STC errors out on an ambiguous 
method reference even if the method type isn't:

{code}
// AWS SDK 2 DynamoDbTable
class DynamoDbTable {
  void putItem(PutItemRequest<T>)
  void putItem(Consumer<PutItemRequest.Builder<T>)
  void putItem(T)
}


@CompileStatic
class MyServiceClass {
  void doThing() {
    Try.success(putItemRequest())
      .andThenTry(table::putItem) // T for Try<T> is PutItemRequest<I>
  }
}
{code}

produces

{code}
[Static type checking] - Reference to method is ambiguous. Cannot choose 
between [Try<T> Try#andThenTry(Consumer<? super T>), Try<T> 
Try#andThenTry(Runnable)]
{code}

I think this may have something to do with the relaxed SAM matching that is 
used to bridge ambiguous closure syntax, but when a plain method reference is 
used, there's no ambiguity available.


> STC: Callable, Runnable, Serializable overload preference for functional 
> argument (closure, lambda, etc.): closure/lambda selection
> -----------------------------------------------------------------------------------------------------------------------------------
>
>                 Key: GROOVY-12759
>                 URL: https://issues.apache.org/jira/browse/GROOVY-12759
>             Project: Groovy
>          Issue Type: Bug
>          Components: Static compilation
>            Reporter: Christopher Smith
>            Assignee: Paul King
>            Priority: Major
>             Fix For: 7.0.0-alpha-1
>
>
> This clone is for work done in Groovy 7: closure/lambda selection 76d6bfc5a9
> Original issue appears below.
> This appears to be similar to GROOVY-9881, but it's specifically in the 
> method-overload procedure. Given a functional value type with two method 
> overloads:
> {code}
> interface Try<T> {
>   Try<T> andThenTry(Consumer<? super T>)
>   Try<T> andThenTry(Runnable)
> }
> {code}
> When this code is invoked from static code, the STC errors out on an 
> ambiguous method reference even if the method type isn't:
> {code}
> // AWS SDK 2 DynamoDbTable
> class DynamoDbTable {
>   void putItem(PutItemRequest<T>)
>   void putItem(Consumer<PutItemRequest.Builder<T>)
>   void putItem(T)
> }
> @CompileStatic
> class MyServiceClass {
>   void doThing() {
>     Try.success(putItemRequest())
>       .andThenTry(table::putItem) // T for Try<T> is PutItemRequest<I>
>   }
> }
> {code}
> produces
> {code}
> [Static type checking] - Reference to method is ambiguous. Cannot choose 
> between [Try<T> Try#andThenTry(Consumer<? super T>), Try<T> 
> Try#andThenTry(Runnable)]
> {code}
> I think this may have something to do with the relaxed SAM matching that is 
> used to bridge ambiguous closure syntax, but when a plain method reference is 
> used, there's no ambiguity available.



--
This message was sent by Atlassian Jira
(v10.3.26#10030026)

Reply via email to