Details
-
Bug
-
Status: Resolved
-
Minor
-
Resolution: Fixed
-
None
-
None
Description
class Foo { void foo() { float x = (false) ? 10.4: null; } } public class Main { public static void main(String[] args) { new Foo().foo(); } }
Actual Behaviour
groovyc compiles this program, but the programs crashes with the following error
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)
Expected Behaviour
groovyc should reject the program with a compile-time error.
Tested against https://github.com/apache/groovy/commit/9bce2dff2068f6ee31c0681b30628987aab09a92
Attachments
Issue Links
- relates to
-
GROOVY-10359 STC misses type error when involving a variable with a char a declared type
-
- Open
-
-
GROOVY-11371 unsafe conversion of array of reference type to an array of primitive type
-
- Resolved
-