Groovy
  1. Groovy
  2. GROOVY-4700

@Field variable can't be referred from closure

    Details

    • Type: Bug Bug
    • Status: 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

      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. Fixed_GROOVY-4700.patch
        6 kB
        Cédric Champeau
      2. bug.groovy
        0.1 kB
        UEHARA Junji

        Activity

        UEHARA Junji created issue -
        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
        Cédric Champeau made changes -
        Field Original Value New Value
        Attachment Fixed_GROOVY-4700.patch [ 54446 ]
        Paul King made changes -
        Assignee Paul King [ paulk ]
        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 Delcroix added a comment -

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

        Show
        Guillaume Delcroix 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.
        Paul King made changes -
        Fix Version/s 1.8-rc-4 [ 17245 ]
        Resolution Fixed [ 1 ]
        Status Open [ 1 ] Resolved [ 5 ]
        Paul King made changes -
        Status Resolved [ 5 ] Closed [ 6 ]
        Mark Thomas made changes -
        Project Import Sun Apr 05 13:32:57 UTC 2015 [ 1428240777691 ]
        Mark Thomas made changes -
        Workflow jira [ 12733631 ] Default workflow, editable Closed status [ 12745408 ]
        Mark Thomas made changes -
        Project Import Mon Apr 06 02:11:23 UTC 2015 [ 1428286283443 ]
        Mark Thomas made changes -
        Workflow jira [ 12971132 ] Default workflow, editable Closed status [ 12978894 ]
        Transition Time In Source Status Execution Times Last Executer Last Execution Date
        Open Open Resolved Resolved
        30d 8h 44m 1 Paul King 30/Mar/11 18:19
        Resolved Resolved Closed Closed
        13d 21h 14m 1 Paul King 13/Apr/11 15:33

          People

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

            Dates

            • Created:
              Updated:
              Resolved:

              Development