Bug #16520
closedBrackets ignored over multi-line
Description
I was refactoring some code in a gem and noticed some test failures. It appears to be a bug in the tests masked by what I believe is a bug in the Ruby parser/interpreter. I've been able to boil the issue down to the following simple example:
# with variable assignment (expected result => 3)
a = (1
+2)
=> 2
# variable is assigned to the value from the second line (expected result also => 3)
a
=> 2
# without variable assignment (expected result => 3)
(1
+2)
=> 2
# with a trailing operator (works as expected, result => 3)
(1+
2)
=> 3
The Ruby interpreter seems to be ignoring the variable on the first line when an operation is split across multiple lines and the operator is on the following line despite the brackets suggesting that the operation is incomplete.
In a similar (possibly unrelated) vein, the following also results in an unexpected behaviour:
[1
+2]
Resulting in the following error raised:
SyntaxError ((irb):2: syntax error, unexpected unary+, expecting ']')
Expected result would have been
=> [3]
Note: I've also tried this on versions as far back as 1.9.3 with the same result.