[
https://issues.apache.org/jira/browse/GROOVY-10930?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Paul King closed GROOVY-10930.
------------------------------
> STC accepts program although constructor reference is invalid
> -------------------------------------------------------------
>
> Key: GROOVY-10930
> URL: https://issues.apache.org/jira/browse/GROOVY-10930
> Project: Groovy
> Issue Type: Bug
> Components: Static Type Checker
> Reporter: Thodoris Sotiropoulos
> Assignee: Eric Milles
> Priority: Major
> Fix For: 5.0.0-alpha-1
>
>
> I have the following program
> {code}
> 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")
> }
> }
> {code}
> h3. Actual behavior
> The compiler accepts the program, but notice that the constructor reference
> is invalid. So, at runtime, we get:
> {code}
> 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)
> {code}
> h3. Expected behavior
> The compiler should have rejected this example program.
> Tested against master (commit: 2c40df2827b8d1bc941bd6ebdc386b3f9bc3bf3b)
--
This message was sent by Atlassian Jira
(v8.20.10#820010)