Details

    • Type: Improvement Improvement
    • Status: Closed Closed
    • Priority: Minor Minor
    • Resolution: Fixed
    • Affects Version/s: 1.0-beta-2
    • Fix Version/s: 1.0-beta-3
    • Component/s: parser
    • Labels:
      None
    • Number of attachments :
      0

      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?

        Activity

        Hide
        james strachan added a comment -

        The only thing to watch in this example is if the closure really is a return value.

        e.g.

        foo() {
        c = 0

        { c = 9 }

        }

        would return the closure

        Show
        james strachan added a comment - The only thing to watch in this example is if the closure really is a return value. e.g. foo() { c = 0 { c = 9 } } would return the closure

          People

          • Assignee:
            bob mcwhirter
            Reporter:
            John Wilson
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: