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

Compile static forces 'as' when trying to make array of nulls

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 2.0.5
    • 2.0.6
    • Static compilation
    • None

    Description

      The following:

      @groovy.transform.CompileStatic
      Integer[] m() {
        Integer[] arr = [ null, null ]
      }
      
      println m()
      

      Throws:

      [Static type checking] - Cannot assign value of type java.lang.Object into array of type [Ljava.lang.Integer;
      

      To get it to work, either remove CompileStatic, or change the function to:

      @groovy.transform.CompileStatic
      Integer[] m() {
        Integer[] arr = [ null, null ] as Integer[]
      }
      
      println m()
      

      Attachments

        Activity

          People

            melix Cédric Champeau
            tim_yates Tim Yates
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: