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

@CompileStatic changes scope of for loop variable

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Blocker
    • Resolution: Fixed
    • 2.0.5
    • 2.0.6
    • Compiler
    • None
    • Debian Unstable, Groovy master/HEAD

    Description

      The script:

      def execute() {
          for (def i = 0; i < 4; ++i) { println i }
      }
      
      execute()
      

      works exactly as expected. However:

      import groovy.transform.CompileStatic
      
      @CompileStatic execute() {
          for (def i = 0; i < 4; ++i) { println i }
      }
      
      execute()
      

      creates an infinite loop in which the value of i is always 0.

      Attachments

        Activity

          People

            melix Cédric Champeau
            russel Dr. Russel Winder
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: