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

Ambiguous method reference when expecting a SAM type

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Open
    • Minor
    • Resolution: Unresolved
    • None
    • None
    • Static Type Checker
    • None

    Description

      I have the following program

      import java.util.function.*;
      
      
      class Main {
        static final void test() {
          from(Main::m);
        }
      
        static <K, V> void from(Function<K, V> f) {}
        static <V> void from(Supplier<V> f) {}
      
        static int m(String x) { return 1; }
      }
      

      Actual behavior

      org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
      test.groovy: 6: [Static type checking] - Reference to method is ambiguous. Cannot choose between [void Main#from(java.util.function.Supplier<V>), void Main#from(java.util.function.Function<K, V>)]
       @ line 6, column 5.
             from(Main::m);
             ^
      
      1 error
      

      Expected behavior

      Compile successfully

      Notes

      Tested against master (commit: 5bcd83e0fde722971f97d479f1a4d6da6cd4aa5f)

      Test case adapted from (Guava library)

      import java.util.function.*;
      
      class Main {
        static final void test() {
          com.google.common.cache.CacheLoader.from(Main::m);
        }
      }
      

      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: