Details
-
Bug
-
Status: Closed
-
Major
-
Resolution: Fixed
-
None
-
None
Description
I have the following program
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() } }
Actual behaviour
The compiler mistakenly compiles this program, but produces a CCE at runtime.
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)
Expected behaviour
The compiler should reject this program.
Tested against master.
Also note that this bug exists since Groovy v3.0.8.
Attachments
Issue Links
- relates to
-
GROOVY-8168 When using Interface: BigDecimal cannot be cast to Double
- Closed
-
GROOVY-10372 STC: check lambda or closure parameter types against target method
- Closed