You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Eric Milles (Jira)" <ji...@apache.org> on 2021/11/16 18:30:00 UTC
[jira] [Resolved] (GROOVY-10277) STC fails to catch type error on the return type of lambdas
[ https://issues.apache.org/jira/browse/GROOVY-10277?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Eric Milles resolved GROOVY-10277.
----------------------------------
Fix Version/s: 4.0.0-beta-3
Resolution: Fixed
https://github.com/apache/groovy/commit/eb8854afcf02057f70b8a979a873e0a34393b740
> 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-beta-3
>
>
> 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)