From: "matz (Yukihiro Matsumoto)" Date: 2021-08-19T07:18:04+00:00 Subject: [ruby-core:104996] [Ruby master Bug#15404] Endless range has inconsistent chaining behaviour Issue #15404 has been updated by matz (Yukihiro Matsumoto). Status changed from Open to Rejected I think it's OK to keep the current behavior. `1.. ..2` looks weird, I agree, but don't need to be a syntax error. Matz. ---------------------------------------- Bug #15404: Endless range has inconsistent chaining behaviour https://bugs.ruby-lang.org/issues/15404#change-93395 * Author: valich (Valentin Fondaratov) * Status: Rejected * Priority: Normal * ruby -v: ruby 2.6.0rc1 (2018-12-06 trunk 66253) [x86_64-linux] * Backport: 2.4: UNKNOWN, 2.5: UNKNOWN ---------------------------------------- Everything below is tested on `Ruby 2.6.0-rc1`. Particular sexp column coordinates are wrong because I've had some leading spaces in the file, sorry. ## The essence of the bug Syntactically, chaining normal ranges is prohibited. For example, `(1..1)..1` produces the following sexp output: ``` [:program, [[:dot2, [:paren, [[:dot2, [:@int, "1", [1, 16]], [:@int, "1", [1, 19]]]]], [:@int, "1", [1, 23]]]]] ``` while `1..1..1` is a syntax error (compiler output: `syntax error, unexpected ..`) New endless ranges break this behaviour and allow chaining. There are two bugs. 1. Chaining is possible on one line: `1.. ..1` is parsed as ``` [:program, [[:dot2, [:dot2, [:@int, "1", [1, 15]], nil], [:@int, "1", [1, 21]]]]] ``` I think this is inconsistent compared to the previous case. 2. Chaining works even with newline between two parts: ``` 1.. ..1 ``` ``` [:program, [[:dot2, [:dot2, [:@int, "1", [1, 15]], nil], [:@int, "1", [2, 17]]]]] ``` This behaviour is completely counterintuitive because `1..` on the first line is a complete statement. Even if it continues to the next line with the search for the right part of expression (end range), it should break because `..1` is not a syntactically valid range end. So, in the search for the end range parser decides to complete the first range and use it as a beginning. It contradicts older ``` 1 ..2 ``` behaviour which effectively meant that a range could not be continued to the next line. ## Why it's important All the code above will break on runtime because it leads to `bad value for range (ArgumentError)`. However, if the code is located in some method (or branch) which is executed rarely, developer might miss the problem. -- https://bugs.ruby-lang.org/ Unsubscribe: