[
https://issues.apache.org/jira/browse/GROOVY-10714?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17644373#comment-17644373
]
Eric Milles edited comment on GROOVY-10714 at 12/7/22 2:45 PM:
---------------------------------------------------------------
>From our correspondence:
{code:groovy}
@Grab('io.vavr:vavr:0.10.4')
import io.vavr.control.Try
@groovy.transform.ToString
class Id {
}
Id resolveId() {
new Id()
}
@groovy.transform.CompileStatic
Try<?> test() {
Try.of(this.&resolveId).andThenTry{ Id id -> id.toString() }
}
print test() // prints "Success(Id())"
{code}
Replacing "andThenTry" with "andThen" demonstrates the selection of
{{andThen(Runnable)}} over {{andThen(Consumer)}}. "andThenTry" uses
{{CheckedConsumer}} and {{CheckedRunnable}} so there is no preference given to
{{Closure}}.
https://www.javadoc.io/static/io.vavr/vavr/0.10.4/io/vavr/control/Try.html#andThen-java.util.function.Consumer-
was (Author: emilles):
>From our correspondence:
{code:groovy}
@Grab('io.vavr:vavr:0.10.4')
import io.vavr.control.Try
@groovy.transform.ToString
class Id {
}
Id resolveId() {
new Id()
}
@groovy.transform.CompileStatic
Try<?> test() {
Try.of(this.&resolveId).andThenTry{ Id id -> id.toString() }
}
print test() // prints "Success(Id())"
{code}
Replacing "andThenTry" with "andThen" demonstrates the selection of
{{andThen(Runnable)} over {{andThen(Consumer)}}. "andThenTry" uses
{{CheckedConsumer}} and {{CheckedRunnable}} so there is no preference given to
{{Closure}}.
https://www.javadoc.io/static/io.vavr/vavr/0.10.4/io/vavr/control/Try.html#andThen-java.util.function.Consumer-
> STC can't distinguish overloads
> -------------------------------
>
> Key: GROOVY-10714
> URL: https://issues.apache.org/jira/browse/GROOVY-10714
> Project: Groovy
> Issue Type: Bug
> Components: Static compilation
> Affects Versions: 4.0.4
> Reporter: Christopher Smith
> Assignee: Eric Milles
> Priority: Minor
>
> 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
(v8.20.10#820010)