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

Ternary returning a list gets parsed improperly

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Open
    • Minor
    • Resolution: Unresolved
    • 4.0.4
    • None
    • parser, parser-antlr4
    • None

    Description

      Another problem with ternary operator, this time almost surely a clash with the safe index operator:

      2034 ocs /tmp> >q.groovy 
      1>2?[1]:0
      2035 ocs /tmp> /usr/local/groovy-4.0.4/bin/groovy q   
      org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
      /private/tmp/q.groovy: 1: Unexpected input: ':' @ line 1, column 8.
         1>2?[1]:0
                ^
      1 error
      2036 ocs /tmp> 
      

      Most probably affects 4 from the beginning. Used to work properly in previous versions (including Groovy 3 which supported the safe index operator all right).

      The issue can be fixed easily e.g. inserting a space betwixt ? and [, thus the minor priority. Nevertheless it is somewhat inconvenient since the operation is pretty common and frequently occurs in the current codebase, which worked under 3 all right. Also, it is sort of difficult to solve it (semi-)automatically, for it is not entirely trivial to distinguish real safe indices from ternaries automatically without a full-fledged parser

      Attachments

        Issue Links

          Activity

            People

              Unassigned Unassigned
              oc OC
              Votes:
              1 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated: