[前][次][番号順一覧][スレッド一覧]

ruby-changes:51405

From: nobu <ko1@a...>
Date: Fri, 8 Jun 2018 20:03:45 +0900 (JST)
Subject: [ruby-changes:51405] nobu:r63611 (trunk): ast.c: fix calls

nobu	2018-06-08 20:03:39 +0900 (Fri, 08 Jun 2018)

  New Revision: 63611

  https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=63611

  Log:
    ast.c: fix calls
    
    * ast.c (node_children): fix the member for method IDs as nd_mid.

  Modified files:
    trunk/ast.c
    trunk/test/ruby/test_ast.rb
Index: ast.c
===================================================================
--- ast.c	(revision 63610)
+++ ast.c	(revision 63611)
@@ -298,13 +298,13 @@ node_children(rb_ast_t *ast, NODE *node) https://github.com/ruby/ruby/blob/trunk/ast.c#L298
       case NODE_OPCALL:
       case NODE_QCALL:
         return rb_ary_new_from_args(3, NEW_CHILD(ast, node->nd_recv),
-                                    ID2SYM(node->nd_vid),
+                                    ID2SYM(node->nd_mid),
                                     NEW_CHILD(ast, node->nd_args));
       case NODE_FCALL:
-        return rb_ary_new_from_args(2, ID2SYM(node->nd_vid),
+        return rb_ary_new_from_args(2, ID2SYM(node->nd_mid),
                                     NEW_CHILD(ast, node->nd_args));
       case NODE_VCALL:
-        return rb_ary_new_from_args(1, ID2SYM(node->nd_vid));
+        return rb_ary_new_from_args(1, ID2SYM(node->nd_mid));
       case NODE_SUPER:
         return rb_ary_new_from_node_args(ast, 1, node->nd_args);
       case NODE_ZSUPER:
Index: test/ruby/test_ast.rb
===================================================================
--- test/ruby/test_ast.rb	(revision 63610)
+++ test/ruby/test_ast.rb	(revision 63611)
@@ -178,4 +178,32 @@ class TestAst < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_ast.rb#L178
     assert_equal([:x], lv)
     assert_equal("NODE_LASGN", body.type)
   end
+
+  def test_call
+    node = RubyVM::AST.parse("nil.foo")
+    _, _, body = *node.children
+    assert_equal("NODE_CALL", body.type)
+    recv, mid, args = body.children
+    assert_equal("NODE_NIL", recv.type)
+    assert_equal(:foo, mid)
+    assert_nil(args)
+  end
+
+  def test_fcall
+    node = RubyVM::AST.parse("foo()")
+    _, _, body = *node.children
+    assert_equal("NODE_FCALL", body.type)
+    mid, args = body.children
+    assert_equal(:foo, mid)
+    assert_nil(args)
+  end
+
+  def test_vcall
+    node = RubyVM::AST.parse("foo")
+    _, _, body = *node.children
+    assert_equal("NODE_VCALL", body.type)
+    mid, args = body.children
+    assert_equal(:foo, mid)
+    assert_nil(args)
+  end
 end

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]