Issue #16520 has been updated by mame (Yusuke Endoh).

Status changed from Open to Rejected

```
(1
+2)
```

is equivalent to

```
begin
  1
  +2
end
```

which evaluates, discards the first line (`1`), and then evaluates and returns the second line (`+2`).

You can see a warning "unused literal ignored" on a verbose mode.

```
$ ruby -w -e 'a = (1
+2)'
-e:1: warning: unused literal ignored
```

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

* 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>