[ruby-dev:49477] [Ruby trunk - Bug #10653] do-end block in ternary operator is syntax error

From: whitequark@...
Date: 2016-01-09 11:26:45 UTC
List: ruby-dev #49477
Issue #10653 has been updated by whitequark *.


I was implementing this in my Ruby parser and I found a much simpler solution than what you've implemented here: https://github.com/whitequark/parser/commit/113442eff1f9c6f7e7205ec0dac8cb858b3b0fc7

In short, instead of explicitly enumerating all contexts where a label is valid, I only disallow quoted label at EXPR_VALUE using an additional flag. It works just as well. It also would not exhibit the bug with %w during backport.

Might I suggest a simplification to parse.y?


----------------------------------------
Bug #10653: do-end block in ternary operator is syntax error 
https://bugs.ruby-lang.org/issues/10653#change-56032

* Author: Shinta Koyanagi
* Status: Closed
* Priority: Normal
* Assignee: Yukihiro Matsumoto
* ruby -v: ruby 2.2.0p0 (2014-12-25 revision 49005) [x86_64-darwin14]
* Backport: 2.0.0: DONTNEED, 2.1: DONTNEED, 2.2: DONE
----------------------------------------
- For example

```
ruby -v -e 'true ? 1.tap do |n| p n end : 0'
```

- Result by 2.1.5

```
ruby 2.1.5p273 (2014-11-13 revision 48405) [x86_64-darwin14.0]
1
```

- Result by 2.2.0

```
ruby 2.2.0p0 (2014-12-25 revision 49005) [x86_64-darwin14]
-e:1: syntax error, unexpected keyword_do_cond, expecting ':'
true ? 1.tap do |n| p n end : 0
               ^
-e:1: syntax error, unexpected tIDENTIFIER, expecting keyword_do or '{' or '('
true ? 1.tap do |n| p n end : 0
                       ^
```



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

In This Thread

Prev Next