groovy
  1. groovy
  2. GROOVY-4700

@Field variable can't be referred from closure

    Details

    • Type: Bug Bug
    • Status: Closed Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 1.8-rc-1
    • Fix Version/s: 1.8-rc-4
    • Component/s: None
    • Labels:
      None
    • Environment:
      Mac OS X
    • Number of attachments :
      2

      Description

      attached code

      import groovy.transform.Field
      
      @Field def xxx = 3
      
      foo = {
        println xxx
      }
      
      foo()
      
      

      generate following error:

      Caught: BUG! exception in phase 'class generation' in source unit '/Users/uehaj/tmp/bug.groovy' tried to get a variable with the name xxx as stack variable, but a variable with this name was not created

      1. bug.groovy
        0.1 kB
        UEHARA Junji
      2. Fixed_GROOVY-4700.patch
        6 kB
        CÚdric Champeau

        Activity

        Hide
        CÚdric Champeau added a comment -

        The following patch (with tests) fixes this issue

        Show
        CÚdric Champeau added a comment - The following patch (with tests) fixes this issue
        Hide
        Paul King added a comment - - edited

        CÚdric's patch looks good to me. Applied in trunk. I also think it is a serious enough bug to warrant merging into 1.8 RC4 but will await Guillaume and Jochen's review/comments.

        Show
        Paul King added a comment - - edited CÚdric's patch looks good to me. Applied in trunk. I also think it is a serious enough bug to warrant merging into 1.8 RC4 but will await Guillaume and Jochen's review/comments.
        Hide
        CÚdric Champeau added a comment -

        Thanks Paul. I looked at your commit, and you accidently changed a test case : in testFieldShouldBeAccessibleFromClosureWithoutAssignment, you added an assignment to

        foo  = { ... }

        , adding a "def" which changes the BinaryExpression into a DeclarationExpression. I think it's important to test both, because I had a fix that only dealt with the DeclarationExpression first and it didn't work with the BinaryExpression, that is to say the script which is attached as a proof for this bug

        Show
        CÚdric Champeau added a comment - Thanks Paul. I looked at your commit, and you accidently changed a test case : in testFieldShouldBeAccessibleFromClosureWithoutAssignment , you added an assignment to foo = { ... } , adding a "def" which changes the BinaryExpression into a DeclarationExpression . I think it's important to test both, because I had a fix that only dealt with the DeclarationExpression first and it didn't work with the BinaryExpression , that is to say the script which is attached as a proof for this bug
        Hide
        Paul King added a comment -

        well the change was deliberate but the consequence was not so I changed it back

        Show
        Paul King added a comment - well the change was deliberate but the consequence was not so I changed it back
        Hide
        Guillaume Laforge added a comment -

        I think that would be good in 1.8 too.
        We'll have to release an RC-4.

        Show
        Guillaume Laforge added a comment - I think that would be good in 1.8 too. We'll have to release an RC-4.
        Hide
        Paul King added a comment -

        merged in preparation for RC4. Thanks to everyone involved.

        Show
        Paul King added a comment - merged in preparation for RC4. Thanks to everyone involved.

          People

          • Assignee:
            Paul King
            Reporter:
            UEHARA Junji
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: