groovy
  1. groovy
  2. GROOVY-4290

Parse error when using method call w/o parens in method-level annotation closure

    Details

    • Type: Bug Bug
    • Status: Closed Closed
    • Priority: Major Major
    • Resolution: Duplicate
    • Affects Version/s: None
    • Fix Version/s: 1.8.4, 2.0-beta-1
    • Component/s: parser-antlr
    • Labels:
      None
    • Number of attachments :
      0

      Description

      The following code:

      class Foo {
        @Bar({ sleep 1 })
        def baz() {}
      }
      

      gives this error:

      unexpected token: @ at line: 2, column: 3
      

      The error goes away when the argument in enclosed in parens:

      class Foo {
        @Bar({ sleep(1) })
        def baz() {}
      }
      

      Any other code changes (like adding explicit closure params) don't help. Class-level annotations don't have this problem. Anyone got an idea what's causing this?

        Activity

        Hide
        Roshan Dawrani added a comment -

        Such w/o parens method call expression does not work in annotations on the field declarations as well.

        class Foo {
            @Bar({ sleep 1 }) 
            int x 
        }
        
        Show
        Roshan Dawrani added a comment - Such w/o parens method call expression does not work in annotations on the field declarations as well. class Foo { @Bar({ sleep 1 }) int x }
        Hide
        Peter Niederwieser added a comment -

        Who's got the know-how to fix this bug? I tried to debug the generated parser but got lost. There seems to be good tool support for ANTLR 3.0 but not for 2.7.

        Show
        Peter Niederwieser added a comment - Who's got the know-how to fix this bug? I tried to debug the generated parser but got lost. There seems to be good tool support for ANTLR 3.0 but not for 2.7.
        Hide
        Roshan Dawrani added a comment -

        I also debugged the ANTLR generated code a few times but only have been able to see more bugs so far and not find a solution yet.

        Show
        Roshan Dawrani added a comment - I also debugged the ANTLR generated code a few times but only have been able to see more bugs so far and not find a solution yet.
        Hide
        blackdrag blackdrag added a comment -

        it is very possible that a synthetic predicate somewhere is a bit wrong

        Show
        blackdrag blackdrag added a comment - it is very possible that a synthetic predicate somewhere is a bit wrong
        Hide
        Roshan Dawrani added a comment - - edited

        Finally, w/o parens method call expression does not work in annotations on the multiple assignments as well.

        All the failing cases highlighted here have the same underlying reason and the fix should test all these cases are taken care of.

        class Foo {
            def foo() {
                @Bar({ sleep 1 }) 
                def (x, y) = [1, 2] 
            }
        }
        

        fails with

        org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
        ..\Test.groovy: 4: unexpected token: ( @ line 4, column 13.
                   def (x, y) = [1, 2] 
                       ^
        1 error
        

        whereas with parentheses, the above error goes away:

        class Foo {
            def foo() {
                @Bar({ sleep(1) }) 
                def (x, y) = [1, 2] 
            }
        }
        
        Show
        Roshan Dawrani added a comment - - edited Finally, w/o parens method call expression does not work in annotations on the multiple assignments as well. All the failing cases highlighted here have the same underlying reason and the fix should test all these cases are taken care of. class Foo { def foo() { @Bar({ sleep 1 }) def (x, y) = [1, 2] } } fails with org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed: ..\Test.groovy: 4: unexpected token: ( @ line 4, column 13. def (x, y) = [1, 2] ^ 1 error whereas with parentheses, the above error goes away: class Foo { def foo() { @Bar({ sleep(1) }) def (x, y) = [1, 2] } }
        Hide
        blackdrag blackdrag added a comment -

        the fix for GROOVY-4970 fixed this case here too

        Show
        blackdrag blackdrag added a comment - the fix for GROOVY-4970 fixed this case here too

          People

          • Assignee:
            blackdrag blackdrag
            Reporter:
            Peter Niederwieser
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: