Uploaded image for project: 'Groovy'
  1. Groovy
  2. GROOVY-10914

Method ambiguity error even if the given argument has an explicit type

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Information Provided
    • None
    • None
    • Static Type Checker
    • None

    Description

      I have the following 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
        }
      }
      

      Actual behavior

      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
      

      Expected behavior

      Compile successfully

      Tested against master (commit: 5a5726342adeb37a6fbaa8cdcbe2d47dee8dc56c)

      Attachments

        Issue Links

          Activity

            People

              emilles Eric Milles
              theosot Thodoris Sotiropoulos
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: