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

STC resolves wrong method reference

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Minor
    • Resolution: Fixed
    • None
    • 3.0.18, 4.0.12
    • Static Type Checker
    • None

    Description

      This is probably a regression

      I have the following program

      import java.util.function.*;
      
      class Main {
        static final void test() {
          final Function<Double, Double> x = Main::clone;
        }
      
        public static <T> T clone(T x) { return x; }
      
      }
      

      Actual behavior

      org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
      test.groovy: 5: [Static type checking] - Invalid return type: java.lang.Object is not convertible to java.lang.Double
       @ line 5, column 40.
             final Function<Double, Double> x = Main::clone;
                                                ^
      
      1 error
      

      Expected behavior

      Compile successfully

      Notes

      Tested against master (commit: c4ee3ce0661eec7d633fc81281d79c8889b3dc66)

      Test case adapted from:

      import java.util.function.*;
      
      class Main {
        static final void test() {
          Function<Double, Double> x = org.apache.commons.lang3.ObjectUtils::clone;
        }
      }
      

      Attachments

        Activity

          People

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

            Dates

              Created:
              Updated:
              Resolved: