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

Failed to find method when using method reference on a class field

    XMLWordPrintableJSON

Details

    Description

      I have the following program

      import java.util.function.Supplier
      
      interface A {
        Double m()
      }
      interface B extends A {
      }
      class C implements B {
        Integer m() { 42 }
      }
      @groovy.transform.CompileStatic
      class Test {
        B f = new C()
        public void test() {
          Supplier<Integer> s = f::m
          assert s.get() == 42
        }
      }
      

      Actual behavior

      The code is rejected with

      org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
      test.groovy: 17: Failed to find method 'm()' for the type: B @ line 17, column 26.
             Supplier<Double> x = f::m;
                                  ^1 error
       

      Expected behavior

      The code should have been compiled successfully.

       

      Notes

      There are two requirements for this bug:

      1. The type of the receiver should be an interface (e.g., B) that extends the interface where the method is defined.
      2. The receiver should be a field.

      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: