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

CompileStatic & Elvis operator: Cannot assign literal value of type (java.lang.Number or java.lang.Comparable) to variable of type double

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Minor
    • Resolution: Fixed
    • 4.0.5
    • 5.0.0-alpha-3, 4.0.16
    • Compiler
    • None

    Description

      import groovy.transform.CompileStatic
      
      @CompileStatic
      class ElvisLiteralAssign {
          Double x = null
          double y = x?.doubleValue() ?: 0
      } 

      This class fails to compile with error:  [Static type checking] - Cannot assign value of type (java.lang.Number or java.lang.Comparable) to variable of type double

      This affects at least 4.0.10 and 4.0.11, and does not affect 3.0.16 or 3.0.17.

      Attachments

        Issue Links

          Activity

            People

              emilles Eric Milles
              jasongarrett Jason Garrett
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: