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

Parsing seems to have changed in 1.8

Details

    • Bug
    • Status: Closed
    • Minor
    • Resolution: Fixed
    • None
    • 1.8-rc-2, 1.9-beta-1
    • parser
    • None

    Description

      Running this script on the webconsole used to work prior to 1.8

      http://groovyconsole.appspot.com/script/192001

      However, now it fails with an exception:

      Script1.groovy: 83: unexpected token: else @ line 83, column 67.
         1).type == type2 ) token += 2 else false
      

      To get the script working again, you need to change line 83 from:

          if( get(0).type == type1 && get(1).type == type2 ) token += 2 else false
      

      to

          if( get(0).type == type1 && get(1).type == type2 ) { token += 2 } else false
      

      Attachments

        Activity

          In a sense, the behavior is more consistent now, because you always need a separator. In 1.7 you could get by without a separator in some cases (*1) but not in others (*2).

          (*1) if (true) x += 2 else false // works in 1.7 but not in 1.8

          (*2) if (true) x else false // works neither in 1.7 nor in 1.8; either need to wrap x with braces, or add a semicolon after it

          Ideally, neither example would need a separator, similar to statements like if (true) println 1 else println 2.

          pniederw Peter Niederwieser added a comment - In a sense, the behavior is more consistent now, because you always need a separator. In 1.7 you could get by without a separator in some cases (*1) but not in others (*2). (*1) if (true) x += 2 else false // works in 1.7 but not in 1.8 (*2) if (true) x else false // works neither in 1.7 nor in 1.8; either need to wrap x with braces, or add a semicolon after it Ideally, neither example would need a separator, similar to statements like if (true) println 1 else println 2 .

          I added a test case.

          guillaume Guillaume Sauthier added a comment - I added a test case.

          People

            blackdrag Jochen Theodorou
            tim_yates Tim Yates
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: