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 2023/04/15 17:25:00 UTC
[jira] [Updated] (GROOVY-10095) Wrong LUB when involving a numeric constant and null
[ https://issues.apache.org/jira/browse/GROOVY-10095?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Eric Milles updated GROOVY-10095:
---------------------------------
Priority: Minor (was: Major)
> Wrong LUB when involving a numeric constant and null
> ----------------------------------------------------
>
> Key: GROOVY-10095
> URL: https://issues.apache.org/jira/browse/GROOVY-10095
> Project: Groovy
> Issue Type: Bug
> Components: Static Type Checker
> Reporter: Thodoris Sotiropoulos
> Assignee: Eric Milles
> Priority: Minor
>
>
> {code:java}
> class Foo { void foo() {
> float x = (false) ? 10.4: null;
> }
> }
> public class Main {
> public static void main(String[] args) {
> new Foo().foo();
> }
> }
> {code}
> h3. Actual Behaviour
> groovyc compiles this program, but the programs crashes with the following error
> {code:java}
> Exception in thread "main" org.codehaus.groovy.runtime.typehandling.GroovyCastException: Cannot cast object 'null' with class 'null' to class 'float'. Try 'java.lang.Float' instead
> at org.codehaus.groovy.runtime.typehandling.DefaultTypeTransformation.castToNumber(DefaultTypeTransformation.java:175)
> at org.codehaus.groovy.runtime.typehandling.DefaultTypeTransformation.floatUnbox(DefaultTypeTransformation.java:95)
> at Foo.foo(groovy6.groovy:4)
> at Main.main(groovy6.groovy:11)
> {code}
> h3. Expected Behaviour
> groovyc should reject the program with a compile-time error.
>
> Tested against https://github.com/apache/groovy/commit/9bce2dff2068f6ee31c0681b30628987aab09a92
>
--
This message was sent by Atlassian Jira
(v8.20.10#820010)