You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Thodoris Sotiropoulos (Jira)" <ji...@apache.org> on 2023/01/24 14:25:00 UTC

[jira] [Created] (GROOVY-10914) Method ambiguity error even if the given argument has an explicit type

Thodoris Sotiropoulos created GROOVY-10914:
----------------------------------------------

             Summary: Method ambiguity error even if the given argument has an explicit type
                 Key: GROOVY-10914
                 URL: https://issues.apache.org/jira/browse/GROOVY-10914
             Project: Groovy
          Issue Type: Bug
          Components: Static Type Checker
            Reporter: Thodoris Sotiropoulos


I have the following code

{code}
import java.util.function.*;

class Main {
  static final void test() {
    String str = "foo"
    LongConsumer y = str.chars().asLongStream().summaryStatistics();
    str.chars().asLongStream().summaryStatistics().andThen(y); // Does not work

    str.chars().asLongStream().summaryStatistics().andThen((LongConsumer) y); // it works
  }
}
{code}

h3. Actual behavior

{code}
org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
Main.groovy: 8: [Static type checking] - Reference to method is ambiguous. Cannot choose between [java.util.function.IntConsumer java.util.function.IntConsumer#andThen(java.util.function.IntConsumer), java.util.function.LongConsumer java.util.function.LongConsumer#andThen(java.util.function.LongConsumer)]
 @ line 8, column 5.
       str.chars().asLongStream().summaryStatistics().andThen(y); // Does not work
       ^

1 error
{code}

h3. Expected behavior

Compile successfully

Tested against master (commit: 5a5726342adeb37a6fbaa8cdcbe2d47dee8dc56c)



--
This message was sent by Atlassian Jira
(v8.20.10#820010)