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

Static compilation and array type parameter causing compile error

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 2.4.15
    • Fix Version/s: 2.5.0
    • Component/s: None
    • Labels:
      None

      Description

      This seems related to GROOVY-8342 (and possibly GROOVY-8638 and GROOVY-7985). When using an array in a generics parameter, I get static compilation errors for return of a map and also for assignment of return value to a variable.

      package r;
      public class ResultHandle {}
      
      package p
      import groovy.transform.CompileStatic
      import r.ResultHandle
      @CompileStatic
      class Issue {
        protected Map<String, ResultHandle[]> getResultsByType() {
          Map<String, ResultHandle[]> resultsByType = [:]
          // populate resultsByType
          return resultsByType
        }
      }
      

      When I build using Ant, I get the following error:

      Buildfile: ...\Gr8\build.xml
      -init:
      -compile:
          [mkdir] Created dir: ...\Gr8\ant\JavaClasses
        [compile] Compiling 2 source files to ...\Gr8\ant\JavaClasses
        [compile] org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
        [compile] ...\Gr8\src\main\bugs\Groovy1234.groovy: 12: [Static type checking] - Incompatible generic argument types. Cannot assign java.util.LinkedHashMap <java.lang.String, [Lr.ResultHandle;> to: java.util.Map <String, ResultHandle[]>
        [compile]  @ line 12, column 12.
        [compile]        return resultsByType
        [compile]               ^
        [compile] 1 error
      
      BUILD FAILED
      

      Additionally, I would get an error if I assigned the result of the method to a typed variable, like this: Map<String, ResultHandle[]> resultsByType = getResultsByType()

        Attachments

        1. Gr8.zip
          6.21 MB
          Eric Milles

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              emilles Eric Milles
            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: