Details
-
Bug
-
Status: Closed
-
Major
-
Resolution: Fixed
-
None
-
None
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
- relates to
-
GROOVY-10971 STC is looking for the wrong constructor reference
- Closed