diff options
author | manga_osyo <manga.osyo@gmail.com> | 2020-07-07 20:18:18 +0900 |
---|---|---|
committer | Nobuyoshi Nakada <nobu@ruby-lang.org> | 2020-07-08 17:43:04 +0900 |
commit | ff5e66034006a875125581114cce19d46843b32a (patch) | |
tree | c77187300742268bd78e358b5d8ea67e46a52a8e | |
parent | 57cde28c20ac0714b5dfad97414f71d9af373084 (diff) |
Added `NODE_SPECIAL_EXCESSIVE_COMMA` info to `ARGS` of `RubyVM::AbstractSyntaxTree`.
Notes
Notes:
Merged: https://github.com/ruby/ruby/pull/3298
-rw-r--r-- | ast.c | 4 | ||||
-rw-r--r-- | test/ruby/test_ast.rb | 15 |
2 files changed, 18 insertions, 1 deletions
@@ -547,7 +547,9 @@ node_children(rb_ast_t *ast, NODE *node) var_name(ainfo->first_post_arg), INT2NUM(ainfo->post_args_num), NEW_CHILD(ast, ainfo->post_init), - var_name(ainfo->rest_arg), + (ainfo->rest_arg == NODE_SPECIAL_EXCESSIVE_COMMA + ? ID2SYM(rb_intern("NODE_SPECIAL_EXCESSIVE_COMMA")) + : var_name(ainfo->rest_arg)), (ainfo->no_kwarg ? Qfalse : NEW_CHILD(ast, ainfo->kw_args)), (ainfo->no_kwarg ? Qfalse : NEW_CHILD(ast, ainfo->kw_rest_arg)), var_name(ainfo->block_arg)); diff --git a/test/ruby/test_ast.rb b/test/ruby/test_ast.rb index da7dde4a38..0d846b76e4 100644 --- a/test/ruby/test_ast.rb +++ b/test/ruby/test_ast.rb @@ -330,4 +330,19 @@ class TestAst < Test::Unit::TestCase assert_equal(:+, op) assert_equal(:VCALL, value.type) end + + def test_args + rest = 6 + node = RubyVM::AbstractSyntaxTree.parse("proc { |a| }") + _, args = *node.children.last.children[1].children + assert_equal(nil, args.children[rest]) + + node = RubyVM::AbstractSyntaxTree.parse("proc { |a,| }") + _, args = *node.children.last.children[1].children + assert_equal(:NODE_SPECIAL_EXCESSIVE_COMMA, args.children[rest]) + + node = RubyVM::AbstractSyntaxTree.parse("proc { |*a| }") + _, args = *node.children.last.children[1].children + assert_equal(:a, args.children[rest]) + end end |