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

Inline conditional List << not being executed fully.

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Won't Fix
    • 1.0-JSR-6
    • 1.1-rc-1
    • None
    • None
    • WinXP SP2
      Groovy Version: 1.0-RC-01-SNAPSHOT JVM: 1.4.2_08-b03

    Description

      Inline Tertiary (boolean ? x : y) and List.add operator << execution bug

      I don't know if this is a parsing issue or a precedence issue but the following code does not act as expected:

      TestCase:
      ----------------------------------
      def list = []
      list << (true) ? "foo" : "bar"
      println list
      ----------------------------------

      Output:
      ----------------------------------
      [true]
      ----------------------------------

      I would have expected to see ["foo"] in this case.

      Forcing execution with parens seems to be an easy workaround such as:
      list << ((true) ? "foo" : "bar") // list == ["foo"]

      Attachments

        Activity

          People

            paulk Paul King
            rmisek Ryan Misek
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: