Issue #16520 has been updated by abrom (Andrew Bromwich).


Note when running the above code through the parser it's pretty clear why it's breaking, and to be honest i'm not sure if there would be a way to 'fix' it either.. hmmm

```ruby
require 'parser/current'
=> true
code = <<-RUBY
(1
+2)
RUBY
=> "(1\n+ 2)\n"
ast = Parser::CurrentRuby.parse(code)
=> s(:begin,
  s(:int, 1),
  s(:int, 2))
eval code
=> 2
code_2 = <<-RUBY
(1+
2)
RUBY
=> "(1+\n2)\n"
> Parser::CurrentRuby.parse(code_2)
=> s(:begin,
  s(:send,
    s(:int, 1), :+,
    s(:int, 2)))
```

----------------------------------------
Bug #16520: Brackets ignored over multi-line
https://bugs.ruby-lang.org/issues/16520#change-83989

* Author: abrom (Andrew Bromwich)
* Status: Rejected
* Priority: Normal
* Assignee: 
* Target version: 
* ruby -v: ruby 2.6.5p114 (2019-10-01 revision 67812) [x86_64-darwin19]
* Backport: 2.5: UNKNOWN, 2.6: UNKNOWN, 2.7: UNKNOWN
----------------------------------------
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:

``` ruby
# 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:
```ruby
[1
+2]
```
Resulting in the following error raised:
> SyntaxError ((irb):2: syntax error, unexpected unary+, expecting ']')

Expected result would have been
```ruby
=> [3]
```

Note: I've also tried this on versions as far back as 1.9.3 with the same result.



-- 
https://bugs.ruby-lang.org/

Unsubscribe: <mailto:ruby-core-request / ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>