aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoryui-knk <yui-knk@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-06-28 14:33:28 +0000
committeryui-knk <yui-knk@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-06-28 14:33:28 +0000
commit47d46675a771a47a678d96b9a1cde60ac52c33b4 (patch)
treee98e1f57bf36a86563a93d9b2e6e93bd1c2a4b03
parent389e82bf18461d0d5ba0576c4209fcba73a22df8 (diff)
downloadruby-47d46675a771a47a678d96b9a1cde60ac52c33b4.tar.gz
ast.c: Fix defs
* 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
-rw-r--r--ast.c4
-rw-r--r--test/ruby/test_ast.rb19
2 files changed, 21 insertions, 2 deletions
diff --git a/ast.c b/ast.c
index 3a89686d10..054d84aeb0 100644
--- a/ast.c
+++ b/ast.c
@@ -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:
diff --git a/test/ruby/test_ast.rb b/test/ruby/test_ast.rb
index cbc3231dd3..f59b54c17a 100644
--- a/test/ruby/test_ast.rb
+++ b/test/ruby/test_ast.rb
@@ -204,4 +204,23 @@ class TestAst < Test::Unit::TestCase
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