ruby-changes:64528
From: Nobuyoshi <ko1@a...>
Date: Thu, 24 Dec 2020 01:40:23 +0900 (JST)
Subject: [ruby-changes:64528] 4a8ff22f0c (master): Reset paren_nest at tAREF and tASET [Bug #17431]
https://git.ruby-lang.org/ruby.git/commit/?id=4a8ff22f0c From 4a8ff22f0c9f8a7cd9a68f49523fa2573a4326e9 Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada <nobu@r...> Date: Thu, 24 Dec 2020 01:25:22 +0900 Subject: Reset paren_nest at tAREF and tASET [Bug #17431] diff --git a/parse.y b/parse.y index c65a469..570a400 100644 --- a/parse.y +++ b/parse.y @@ -9668,6 +9668,7 @@ parser_yylex(struct parser_params *p) https://github.com/ruby/ruby/blob/trunk/parse.y#L9668 p->lex.paren_nest++; if (IS_AFTER_OPERATOR()) { if ((c = nextc(p)) == ']') { + p->lex.paren_nest--; SET_LEX_STATE(EXPR_ARG); if ((c = nextc(p)) == '=') { return tASET; diff --git a/test/ruby/test_syntax.rb b/test/ruby/test_syntax.rb index 73c15f8..e289eea 100644 --- a/test/ruby/test_syntax.rb +++ b/test/ruby/test_syntax.rb @@ -619,6 +619,11 @@ WARN https://github.com/ruby/ruby/blob/trunk/test/ruby/test_syntax.rb#L619 def test_do_block_after_lambda bug11380 = '[ruby-core:70067] [Bug #11380]' assert_valid_syntax('p -> { :hello }, a: 1 do end', bug11380) + + assert_valid_syntax('->(opt = (foo.[] bar)) {}') + assert_valid_syntax('->(opt = (foo.[]= bar)) {}') + assert_valid_syntax('->(opt = (foo.[] bar)) do end') + assert_valid_syntax('->(opt = (foo.[]= bar)) do end') end def test_reserved_method_no_args @@ -998,6 +1003,19 @@ eom https://github.com/ruby/ruby/blob/trunk/test/ruby/test_syntax.rb#L1003 assert_warn('') {eval("(1...)")} assert_warn('') {eval("(1...\n2)")} assert_warn('') {eval("{a: 1...\n2}")} + + assert_warn(/\.\.\. at EOL/) do + assert_valid_syntax('foo.[]= ...', verbose: true) + end + assert_warn(/\.\.\. at EOL/) do + assert_valid_syntax('foo.[] ...', verbose: true) + end + assert_warn(/\.\.\. at EOL/) do + assert_syntax_error('foo.[]= bar, ...', /unexpected/, verbose: true) + end + assert_warn(/\.\.\. at EOL/) do + assert_syntax_error('foo.[] bar, ...', /unexpected/, verbose: true) + end end def test_too_big_nth_ref -- cgit v0.10.2 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/