ruby-changes:51568
From: yui-knk <ko1@a...>
Date: Fri, 29 Jun 2018 08:13:57 +0900 (JST)
Subject: [ruby-changes:51568] yui-knk:r63782 (trunk): ast.c: Fix defs
yui-knk 2018-06-28 23:33:28 +0900 (Thu, 28 Jun 2018) New Revision: 63782 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=63782 Log: ast.c: Fix defs * ast.c (node_children): Add mid to children Modified files: trunk/ast.c trunk/test/ruby/test_ast.rb Index: ast.c =================================================================== --- ast.c (revision 63781) +++ ast.c (revision 63782) @@ -374,9 +374,9 @@ node_children(rb_ast_t *ast, NODE *node) https://github.com/ruby/ruby/blob/trunk/ast.c#L374 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: Index: test/ruby/test_ast.rb =================================================================== --- test/ruby/test_ast.rb (revision 63781) +++ test/ruby/test_ast.rb (revision 63782) @@ -204,4 +204,23 @@ class TestAst < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_ast.rb#L204 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 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/