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

VerifyError if a closure shared variable of a foreach style loop is used with @CompileStatic

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Critical
    • Resolution: Fixed
    • 2.4.2
    • 2.4.3
    • Static compilation
    • None

    Description

      There is a regression due to GROOVY-7349. The following code will fail with a VerifyError:

      @CompileStatic
      private void foo(String[] arr) {
          for (String s in arr) {
              { -> println(s)}.call() // make s closure shared
          }
      }
      

      A workaround is to use an intermediate variable:

      @CompileStatic
      private void foo(String[] arr) {
          for (String s in arr) {
              def v = s;
              { -> println(v)}.call()
          }
      }
      

      Attachments

        Activity

          People

            melix Cédric Champeau
            melix Cédric Champeau
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: