mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
Make RubyVM::AbstractSyntaxTree handle **nil syntax
Use false instead of nil for the keyword and keyword rest values in that case.
This commit is contained in:
parent
4d64693c70
commit
fa41a7b260
Notes:
git
2019-08-31 04:40:14 +09:00
2 changed files with 15 additions and 2 deletions
4
ast.c
4
ast.c
|
@ -625,8 +625,8 @@ node_children(rb_ast_t *ast, NODE *node)
|
|||
INT2NUM(ainfo->post_args_num),
|
||||
NEW_CHILD(ast, ainfo->post_init),
|
||||
var_name(ainfo->rest_arg),
|
||||
NEW_CHILD(ast, ainfo->kw_args),
|
||||
NEW_CHILD(ast, ainfo->kw_rest_arg),
|
||||
(ainfo->no_kwarg ? Qfalse : NEW_CHILD(ast, ainfo->kw_args)),
|
||||
(ainfo->no_kwarg ? Qfalse : NEW_CHILD(ast, ainfo->kw_rest_arg)),
|
||||
var_name(ainfo->block_arg));
|
||||
}
|
||||
case NODE_SCOPE:
|
||||
|
|
|
@ -308,4 +308,17 @@ class TestAst < Test::Unit::TestCase
|
|||
type2 = body.children[2]
|
||||
assert_not_equal(type1, type2)
|
||||
end
|
||||
|
||||
def test_keyword_rest
|
||||
kwrest = lambda do |arg_str|
|
||||
node = RubyVM::AbstractSyntaxTree.parse("def a(#{arg_str}) end")
|
||||
node = node.children.last.children.last.children[1].children[-2]
|
||||
node ? node.children : node
|
||||
end
|
||||
|
||||
assert_equal(nil, kwrest.call(''))
|
||||
assert_equal([nil], kwrest.call('**'))
|
||||
assert_equal(false, kwrest.call('**nil'))
|
||||
assert_equal([:a], kwrest.call('**a'))
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue