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

Unexpected compilation error with MapEntryExpression usage - groovy grammar issue?

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 1.8-beta-1
    • 1.7.2, 1.8-beta-1
    • Compiler
    • None

    Description

      The following code compiles fine:

      import java.util.concurrent.*
      class Test {
          def bar () {
              ExecutorService pool = null
              pool.submit(( Runnable ) [ run : { "some statement"; 
                  //println "fishy print"
              }])
          }
      }
      

      But if I uncomment the print statement from inside the closure, like

      import java.util.concurrent.*
      class Test {
          def bar () {
              ExecutorService pool = null
              pool.submit(( Runnable ) [ run : { "some statement"; 
                  println "fishy print"
              }])
          }
      }
      

      I get the following compilation error:

      ...\Try.groovy: 5: You tried to use a map entry for an index operation, this is not allowed. Maybe something should be set in parentheses or a comma is missing?
       @ line 5, column 36.
                 pool.submit(( Runnable ) [ run : { "some statement"; 
      

      Here is the AST formed in 2 cases (2nd case has the wrong AST)

      Case 1: (Successful compilation)

      ArgumentListExpression[
          CastExpression[
              (java.lang.Runnable) 
                  MapExpression[
                      MapEntryExpression(key: ConstantExpression[run], value: ClosureExpression[]{...}
                      )
                  ]
          ]
      ]
      

      Case 2: (Failing compilation)

      ArgumentListExpression[
          BinaryExpression[
              left = ClassExpression[type: java.lang.Runnable]
              operation = "["
              right = MapEntryExpression(key: ConstantExpression[run], value: ClosureExpression[]{...})]]
      

      Attachments

        Activity

          People

            ait Alex Tkachman
            roshandawrani Roshan Dawrani
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: