mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
ast.c: fix calls
* ast.c (node_children): fix the member for method IDs as nd_mid. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63611 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
46d7dc1162
commit
fa409e6cbb
2 changed files with 31 additions and 3 deletions
6
ast.c
6
ast.c
|
@ -298,13 +298,13 @@ node_children(rb_ast_t *ast, NODE *node)
|
|||
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:
|
||||
|
|
|
@ -178,4 +178,32 @@ class TestAst < Test::Unit::TestCase
|
|||
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
|
||||
|
|
Loading…
Reference in a new issue