Issue #15404 has been reported by valich (Valentin Fondaratov). ---------------------------------------- Bug #15404: Endless range has inconsistent chaining behaviour https://bugs.ruby-lang.org/issues/15404 * Author: valich (Valentin Fondaratov) * Status: Open * Priority: Normal * Assignee: * Target version: * ruby -v: 2.6.0-rc1 * 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: <mailto:ruby-core-request / ruby-lang.org?subject=unsubscribe> <http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>