Thodoris Sotiropoulos created GROOVY-11495: ----------------------------------------------
Summary: failing to detect type error when having a method reference with an invalid return Key: GROOVY-11495 URL: https://issues.apache.org/jira/browse/GROOVY-11495 Project: Groovy Issue Type: Bug Components: Static Type Checker Reporter: Thodoris Sotiropoulos I have the following program {code:java} import java.util.function.*; class A<T> { T x; public A(T x) { this.x = x; } } class Test { public static A<String> m(String x) { return new A<>(x); } public static void main(String[] args) { Function<String, A<Integer>> z = Test::m; A<Integer> d = z.apply("fdaf"); Integer x = d.x; } } {code} h3. Actual behavior The code compiles, but there's a runtime error {code:java} Exception in thread "main" org.codehaus.groovy.runtime.typehandling.GroovyCastException: Cannot cast object 'fdaf' with class 'java.lang.String' to class 'java.lang.Integer' at org.codehaus.groovy.runtime.typehandling.DefaultTypeTransformation.castToNumber(DefaultTypeTransformation.java:177) at org.codehaus.groovy.runtime.typehandling.DefaultTypeTransformation.continueCastOnNumber(DefaultTypeTransformation.java:294) at org.codehaus.groovy.runtime.typehandling.DefaultTypeTransformation.castToType(DefaultTypeTransformation.java:248) at org.codehaus.groovy.vmplugin.v8.IndyInterface.fromCache(IndyInterface.java:336) at Test.main(groovy91.groovy:14) {code} h3. Expected behavior The code should have been rejected. -- This message was sent by Atlassian Jira (v8.20.10#820010)