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"]
After looking at the JavaDoc for the List interface, List.add returns a boolean value so it looks to be more of an operator precedence issue.
so at frist glance it seems to be executing like:
(list << (true)) ? "foo" : "bar"
then the "foo" just gets dropped off into no man's land while true is actually added to the list as a side-effect