groovy
  1. groovy
  2. GROOVY-5207

@Field access within closure fails with 'BUG! exception in phase 'class generation' in source unit'

    Details

    • Type: Bug Bug
    • Status: Closed Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 1.8.4
    • Fix Version/s: 1.8.6, 2.0-beta-3
    • Component/s: None
    • Labels:
      None
    • Number of attachments :
      2

      Description

      Looks like accessing @Field fields inside closures has a problem. Please file a bug.

      ---------------------------------------------
      import groovy.transform.Field

      @Field pomProperties = [:]

      "".each

      { pomProperties[1] = 2 }

      ---------------------------------------------
      fails with the same error.
      ---------------------------------------------
      Caught: BUG! exception in phase 'class generation' in source unit 'C:\Temp\m2g.groovy' tried to get a variable with the name pomProperties
      as stack variable, but a variable with this name was not created
      ---------------------------------------------

      1. groovy5207.patch
        41 kB
        Paul King
      2. groovy5207B.patch
        2 kB
        Paul King

        Activity

        Hide
        Paul King added a comment -

        Possible patch attached. It is a little crude in that it runs the VariableScopeVisitor twice. It might be possible to come up with a more efficient alternate approach.

        Show
        Paul King added a comment - Possible patch attached. It is a little crude in that it runs the VariableScopeVisitor twice. It might be possible to come up with a more efficient alternate approach.
        Hide
        Paul King added a comment -

        OK, a slightly nicer patch I think.

        Show
        Paul King added a comment - OK, a slightly nicer patch I think.
        Hide
        Paul King added a comment -

        Closures defined externally from the source unit being compiled didn't correctly access @Field fields. This should be fixed now. Thanks for spotting and reporting the problem.

        Show
        Paul King added a comment - Closures defined externally from the source unit being compiled didn't correctly access @Field fields. This should be fixed now. Thanks for spotting and reporting the problem.

          People

          • Assignee:
            Paul King
            Reporter:
            Ray Suliteanu
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: