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

STC accepts program although constructor reference is invalid

    XMLWordPrintableJSON

Details

    Description

      I have the following program

      import java.util.function.*;
      
      class Bar {}
      
      public class Test {
      
          public static void main(String[] args) {
            m(Bar::new);
          }
      
          static <X> void m(Function<String, X> d) {
            d.apply("dfa")
          }
      }
      

      Actual behavior

      The compiler accepts the program, but notice that the constructor reference is invalid. So, at runtime, we get:

      Exception in thread "main" groovy.lang.GroovyRuntimeException: Could not find matching constructor for: Bar(String)
              at groovy.lang.MetaClassImpl.invokeConstructor(MetaClassImpl.java:1908)
              at groovy.lang.MetaClassImpl.invokeConstructor(MetaClassImpl.java:1677)
              at org.codehaus.groovy.vmplugin.v8.IndyInterface.fromCache(IndyInterface.java:321)
              at Test.ctorRef$main$0(test.groovy)
              at Test.m(test.groovy:13)
              at Test.main(test.groovy:9)
      

      Expected behavior

      The compiler should have rejected this example program.

      Tested against master (commit: 2c40df2827b8d1bc941bd6ebdc386b3f9bc3bf3b)

      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: