Groovy
  1. Groovy
  2. GROOVY-5301

closures do not handle 'it' correctly

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Minor Minor
    • Resolution: Not A Problem
    • Affects Version/s: 1.8.5
    • Fix Version/s: None
    • Component/s: groovy-jdk
    • Labels:
    • Environment:
      Windows command line (to reduce dependencies)

      Description

      Running the following script shows 'it' as being null:

      dec = { it ->
      def x = it
      return { println "$

      {x--}

      (was $it)" }
      }

      def f = dec(2)
      f(); f();

      Output is:
      2 (was null)
      1 (was null)

      If the 'it' references are changed to 'val', then it works fine - i.e. says '(was 2)'

      This also fails when no parameter is used (i.e. defaulting to 'it')

        Activity

        Mark Thomas made changes -
        Workflow jira [ 12971648 ] Default workflow, editable Closed status [ 12979432 ]
        Mark Thomas made changes -
        Project Import Mon Apr 06 02:11:23 UTC 2015 [ 1428286283443 ]
        Mark Thomas made changes -
        Workflow jira [ 12734224 ] Default workflow, editable Closed status [ 12745930 ]
        Mark Thomas made changes -
        Project Import Sun Apr 05 13:32:57 UTC 2015 [ 1428240777691 ]
        Paul King made changes -
        Status Resolved [ 5 ] Closed [ 6 ]
        Andrew Stratton made changes -
        Field Original Value New Value
        Resolution Not A Bug [ 6 ]
        Status Open [ 1 ] Resolved [ 5 ]
        Andrew Stratton created issue -

          People

          • Assignee:
            Unassigned
            Reporter:
            Andrew Stratton
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development