diff options
author | Nobuyoshi Nakada <nobu@ruby-lang.org> | 2020-06-01 23:43:31 +0900 |
---|---|---|
committer | Nobuyoshi Nakada <nobu@ruby-lang.org> | 2020-06-07 18:44:07 +0900 |
commit | c0ba35f3344652bca7768cf37f367ff40f5e973e (patch) | |
tree | 45f379f05871b14d844ce4818886d7e75787a73d | |
parent | 9d24ddbb53b296105177e1badce226c4e575dcc7 (diff) | |
download | ruby-c0ba35f3344652bca7768cf37f367ff40f5e973e.tar.gz |
Differentiate `...` in lambda arguments
-rw-r--r-- | parse.y | 4 | ||||
-rw-r--r-- | test/ruby/test_syntax.rb | 5 |
2 files changed, 7 insertions, 2 deletions
@@ -9365,6 +9365,10 @@ parser_yylex(struct parser_params *p) if (p->lex.paren_nest == 0 && looking_at_eol_p(p)) { rb_warn0("... at EOL, should be parenthesized?"); } + else if (p->lex.lpar_beg >= 0 && p->lex.lpar_beg+1 == p->lex.paren_nest) { + if (IS_lex_state_for(last_state, EXPR_LABEL)) + return tDOT3; + } return is_beg ? tBDOT3 : tDOT3; } pushback(p, c); diff --git a/test/ruby/test_syntax.rb b/test/ruby/test_syntax.rb index cf0a93e185..6245c73ec3 100644 --- a/test/ruby/test_syntax.rb +++ b/test/ruby/test_syntax.rb @@ -1508,10 +1508,11 @@ eom assert_valid_syntax('def nil(...) end') assert_valid_syntax('def true(...) end') assert_valid_syntax('def false(...) end') + unexpected = /unexpected \.{3}/ assert_syntax_error('iter do |...| end', /unexpected/) assert_syntax_error('iter {|...|}', /unexpected/) - assert_syntax_error('->... {}', /unexpected/) - assert_syntax_error('->(...) {}', /unexpected/) + assert_syntax_error('->... {}', unexpected) + assert_syntax_error('->(...) {}', unexpected) assert_syntax_error('def foo(x, y, z) bar(...); end', /unexpected/) assert_syntax_error('def foo(x, y, z) super(...); end', /unexpected/) assert_syntax_error('def foo(...) yield(...); end', /unexpected/) |