summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNobuyoshi Nakada <nobu@ruby-lang.org>2020-12-24 01:25:22 +0900
committerNobuyoshi Nakada <nobu@ruby-lang.org>2020-12-24 01:39:52 +0900
commit4a8ff22f0c9f8a7cd9a68f49523fa2573a4326e9 (patch)
tree592ee65c12d06a02c088616e15c062f5517c4522
parentfb545743932a5efd5a34ed9da981248dae3cc5ff (diff)
Reset paren_nest at tAREF and tASET [Bug #17431]
-rw-r--r--parse.y1
-rw-r--r--test/ruby/test_syntax.rb18
2 files changed, 19 insertions, 0 deletions
diff --git a/parse.y b/parse.y
index c65a469a31..570a400510 100644
--- a/parse.y
+++ b/parse.y
@@ -9668,6 +9668,7 @@ parser_yylex(struct parser_params *p)
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 73c15f8a7f..e289eea2c2 100644
--- a/test/ruby/test_syntax.rb
+++ b/test/ruby/test_syntax.rb
@@ -619,6 +619,11 @@ WARN
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
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