Uploaded image for project: 'Groovy'
  1. Groovy
  2. GROOVY-10095

Wrong LUB when involving a numeric constant and null

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Minor
    • Resolution: Fixed
    • None
    • 5.0.0-alpha-9
    • Static Type Checker
    • 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

          Activity

            People

              emilles Eric Milles
              theosot Thodoris Sotiropoulos
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: