ruby-changes:58745
From: Nobuyoshi <ko1@a...>
Date: Tue, 12 Nov 2019 17:15:12 +0900 (JST)
Subject: [ruby-changes:58745] a58b4eee25 (master): Warn on `...` at EOL
https://git.ruby-lang.org/ruby.git/commit/?id=a58b4eee25 From a58b4eee25b79432d98a1c665edaf5ec0a054b2e Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada <nobu@r...> Date: Tue, 12 Nov 2019 17:14:10 +0900 Subject: Warn on `...` at EOL diff --git a/parse.y b/parse.y index 0bda2d2..6d05644 100644 --- a/parse.y +++ b/parse.y @@ -9235,6 +9235,9 @@ parser_yylex(struct parser_params *p) https://github.com/ruby/ruby/blob/trunk/parse.y#L9235 switch (c = nextc(p)) { case '.': if ((c = nextc(p)) == '.') { + if (p->lex.paren_nest == 0 && looking_at_eol_p(p)) { + rb_warn0("... at EOL, should be parenthesized?"); + } return is_beg ? tBDOT3 : tDOT3; } pushback(p, c); diff --git a/test/ruby/test_syntax.rb b/test/ruby/test_syntax.rb index ba479fa..622017b 100644 --- a/test/ruby/test_syntax.rb +++ b/test/ruby/test_syntax.rb @@ -986,6 +986,13 @@ eom https://github.com/ruby/ruby/blob/trunk/test/ruby/test_syntax.rb#L986 assert_syntax_error('0...%q.', /unterminated string/, bug10957) end + def test_range_at_eol + assert_warn(/\.\.\. at EOL/) {eval("1...\n2")} + assert_warn('') {eval("(1...)")} + assert_warn('') {eval("(1...\n2)")} + assert_warn('') {eval("{a: 1...\n2}")} + end + def test_too_big_nth_ref bug11192 = '[ruby-core:69393] [Bug #11192]' assert_warn(/too big/, bug11192) do -- cgit v0.10.2 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/