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

Block treated as closure

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Closed
    • Minor
    • Resolution: Fixed
    • 1.0-beta-2
    • 1.0-beta-3
    • parser
    • None

    Description

      class Tester {
      static main(args) {
      c = 0

      { c = 9 }
      println(c)
      }
      }

      prints 0

      This is because the code in curly brackets is treated as a closure not as a block.

      If I write

      class Tester {
      static main(args) {
      c = 0
      if (true) { c = 9 }

      println(c)
      }
      }

      then it prints 9

      The behaviour of the compiler isn't really a bug but it is surprising behaviour to a C or Java programmer.

      I can see no use for the construction and immediate discarding of a closure. Would it be possible for the compiler to treat this construct as a block?

      Attachments

        Activity

          People

            bob Bob Paulin
            tug John Wilson
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: