Skip to content

Commit

Permalink
ast.c: Fix defs
Browse files Browse the repository at this point in the history
* ast.c (node_children): Add mid to children

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63782 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
  • Loading branch information
yui-knk committed Jun 28, 2018
1 parent 4aaceb2 commit 63e72a5
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
4 changes: 2 additions & 2 deletions ast.c
Original file line number Diff line number Diff line change
Expand Up @@ -374,9 +374,9 @@ node_children(rb_ast_t *ast, NODE *node)
case NODE_BLOCK_PASS:
return rb_ary_new_from_node_args(ast, 2, node->nd_head, node->nd_body);
case NODE_DEFN:
return rb_ary_new_from_node_args(ast, 1, node->nd_defn);
return rb_ary_new_from_args(2, ID2SYM(node->nd_mid), NEW_CHILD(ast, node->nd_defn));
case NODE_DEFS:
return rb_ary_new_from_node_args(ast, 2, node->nd_recv, node->nd_defn);
return rb_ary_new_from_args(3, NEW_CHILD(ast, node->nd_recv), ID2SYM(node->nd_mid), NEW_CHILD(ast, node->nd_defn));
case NODE_ALIAS:
return rb_ary_new_from_node_args(ast, 2, node->nd_1st, node->nd_2nd);
case NODE_VALIAS:
Expand Down
19 changes: 19 additions & 0 deletions test/ruby/test_ast.rb
Original file line number Diff line number Diff line change
Expand Up @@ -204,4 +204,23 @@ def test_vcall
assert_equal(:foo, mid)
assert_nil(args)
end

def test_defn
node = RubyVM::AST.parse("def a; end")
_, _, body = *node.children
assert_equal("NODE_DEFN", body.type)
mid, defn = body.children
assert_equal(:a, mid)
assert_equal("NODE_SCOPE", defn.type)
end

def test_defs
node = RubyVM::AST.parse("def a.b; end")
_, _, body = *node.children
assert_equal("NODE_DEFS", body.type)
recv, mid, defn = body.children
assert_equal("NODE_VCALL", recv.type)
assert_equal(:b, mid)
assert_equal("NODE_SCOPE", defn.type)
end
end

0 comments on commit 63e72a5

Please sign in to comment.