summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeremy Evans <code@jeremyevans.net>2019-04-24 11:40:02 -0700
committerJeremy Evans <code@jeremyevans.net>2019-08-30 12:39:31 -0700
commitfa41a7b2608523a89d4eb1c9309d39a140e839ef (patch)
tree106484dff969ef1400bfb6c33523e94b88a3a92e
parent4d64693c703edbccc5b155072276ce7b8c3becdb (diff)
downloadruby-fa41a7b2608523a89d4eb1c9309d39a140e839ef.tar.gz
Make RubyVM::AbstractSyntaxTree handle **nil syntax
Use false instead of nil for the keyword and keyword rest values in that case.
-rw-r--r--ast.c4
-rw-r--r--test/ruby/test_ast.rb13
2 files changed, 15 insertions, 2 deletions
diff --git a/ast.c b/ast.c
index 91659a9110..601a819c1b 100644
--- a/ast.c
+++ b/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:
diff --git a/test/ruby/test_ast.rb b/test/ruby/test_ast.rb
index ee9c1ddc00..5c431a47b1 100644
--- a/test/ruby/test_ast.rb
+++ b/test/ruby/test_ast.rb
@@ -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