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

Some ternary expressions with []'s and 'as' are not parsed properly

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Open
    • Priority: Trivial
    • Resolution: Unresolved
    • Affects Version/s: 3.0.3
    • Fix Version/s: None
    • Component/s: parser
    • Labels:
      None

      Description

      Expressions of type “1>2?[3] as Set:null” are not parsed properly, example below. I haven't tried all the versions, but I believe it is a problem caused by the parrot; I've checked 2.4.17 and 2.5.8 and both worked properly.

      There's a very plain work-around, it suffices to enclose the middle part of the expression in parentheses, like “1>2?([3] as Set):null”. Besides, such expressions are pretty rare.

      Far as I understand, the ambiguity of “as” and safe indexing both play their part and it might prove difficult to fix without forbidding “as” usage as identifier, which would break old code in a considerably worse way than this.

      For all these reasons I believe the trivial priority in this case is better than minor, which would technically fit the problem better.

       

      52 ocs /tmp> >q.groovy                           
      1>2?[3] as Set:null
      53 ocs /tmp> /usr/local/groovy-3.0.3/bin/groovy q
      org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
      /private/tmp/q.groovy: 1: Unexpected input: '1>2?[3]' @ line 1, column 1.
         1>2?[3] as Set:null
         ^
      1 error
      54 ocs /tmp> 
      

       

        Attachments

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              oc OC
            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated: