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

Parrot Parser: named arguments does not support all key expressions

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • None
    • 3.0.12, 4.0.4
    • parser-antlr4
    • None

    Description

      This is IMO a regression (wrt. e.g. Groovy 2.4.11), the following does not compile in Groovy 3.0.10.

      def fun = { arg ->
          return arg
      }
      
      fun (
          x: 1,
          [a: 1]: '2'
      )

      This is the combination of the following:

      • map literal is used as an argument of a function, without enclosing brackets (I hope this  is legal)
      • another map literal is used as a key of the outer map (I hope this is legal too)

      If both these preconditions are met, the compiler complains with:

      org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
      index.groovy: 5: Unexpected input: '(' @ line 5, column 5.
         fun (
             ^
      1 error 

      This does compile:

      def fun = { arg ->
          return arg
      }
      
      fun (
          x: 1,
          a: '2'
      )

      So does this:

      def fun = { arg ->
          return arg
      }
      
      fun ([
          x: 1,
          [a: 1]: '2'
      ]) 

      Is this a bug?

      Attachments

        Activity

          People

            daniel_sun Daniel Sun
            michal.sevcenko Michal Ševčenko
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: