[
https://issues.apache.org/jira/browse/GROOVY-10277?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Paul King closed GROOVY-10277.
------------------------------
> STC fails to catch type error on the return type of lambdas
> -----------------------------------------------------------
>
> Key: GROOVY-10277
> URL: https://issues.apache.org/jira/browse/GROOVY-10277
> Project: Groovy
> Issue Type: Bug
> Components: Static Type Checker
> Reporter: Thodoris Sotiropoulos
> Assignee: Eric Milles
> Priority: Major
> Fix For: 4.0.0-rc-1
>
>
> I have the following program
> {code:java}
> import java.util.function.Supplier;
> class Main {
> static void main(String[] args) {
> bar({ -> true}); // should not type-check
> bar({ -> true} as Supplier<Long>); // should not type-check.
> }
> static Long bar(Supplier<Long> x) {
> x.get()
> }
> }
> {code}
> h3. Actual behaviour
> The compiler mistakenly compiles this program, but produces a CCE at runtime.
> {code}
> Exception in thread "main"
> org.codehaus.groovy.runtime.typehandling.GroovyCastException: Cannot cast
> object 'true' with class 'java.lang.Boolean' to class 'java.lang.Long'
> at
> org.codehaus.groovy.runtime.typehandling.DefaultTypeTransformation.castToNumber(DefaultTypeTransformation.java:182)
> at
> org.codehaus.groovy.runtime.typehandling.DefaultTypeTransformation.continueCastOnNumber(DefaultTypeTransformation.java:294)
> at
> org.codehaus.groovy.runtime.typehandling.DefaultTypeTransformation.castToType(DefaultTypeTransformation.java:251)
> at
> org.codehaus.groovy.vmplugin.v8.IndyInterface.fromCache(IndyInterface.java:318)
> at Main.bar(test.groovy:10)
> at Main.main(test.groovy:6)
> {code}
> h3. Expected behaviour
> The compiler should reject this program.
> Tested against master.
> Also note that this bug exists since Groovy v3.0.8.
--
This message was sent by Atlassian Jira
(v8.20.1#820001)