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

Using @CompileStatic on code that uses spread operator on a Set results in compilation error

    XMLWordPrintableJSON

Details

    Description

      The two attached files (bad.groovy & good.groovy) demonstrate the problem. In bad.groovy, a class with the @CompileStatic annotation attempts to collect the objects from a Set<> using the spread operator and fails with the compilation error:

      org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
      bad.groovy: 17: [Static type checking] - No such property: strings for class: java.util.Set <Inner>
      @ line 17, column 13.
      println outer.inners*.strings
      ^

      1 error

      In good.groovy, the equivalent .collect{} is used for the spread operator and it compiles and runs as expected.

      Attachments

        1. bad.groovy
          0.4 kB
          Adam Brown
        2. good.groovy
          0.4 kB
          Adam Brown

        Activity

          People

            blackdrag Jochen Theodorou
            acourtneybrown Adam Brown
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: