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

Cannot assign list to array under static compilation

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Minor
    • Resolution: Duplicate
    • 3.0.15
    • None
    • Compiler
    • None

    Description

      Assigning a List to an Array of the same type does not compile.

      This class:

      package example
      
      import groovy.transform.CompileStatic
      
      @CompileStatic
      class AssignListToArray {
         void doStuff(String[] data) {
            data = data.collect { it }
         }
      } 

      Results in this compilation error:

      src/main/groovy/example/AssignListToArray.groovy: 8: [Static type checking] - Cannot assign value of type java.util.List <java.lang.String> to variable of type java.lang.String[]
       @ line 8, column 10.
                 data = data.collect { it } 

      This class compiles in 2.4.21, 2.5.21, and 3.0.14.

      Attachments

        Issue Links

          Activity

            People

              Unassigned Unassigned
              jasongarrett Jason Garrett
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: