aboutsummaryrefslogtreecommitdiffstats
path: root/vm.c
diff options
context:
space:
mode:
authorYusuke Endoh <mame@ruby-lang.org>2019-03-18 14:25:47 +0900
committerJeremy Evans <code@jeremyevans.net>2019-08-30 12:39:31 -0700
commit16c6984bb97409029e213154ac4f633ae04af3d8 (patch)
tree53839e4d596e4016320097530ff5d7fcf19d11e6 /vm.c
parentb0a291f6f6a5834fd84807eb48be906ade429871 (diff)
downloadruby-16c6984bb97409029e213154ac4f633ae04af3d8.tar.gz
Separate keyword arguments from positional arguments
And, allow non-symbol keys as a keyword arugment
Diffstat (limited to 'vm.c')
-rw-r--r--vm.c16
1 files changed, 6 insertions, 10 deletions
diff --git a/vm.c b/vm.c
index 157a43967e..c727554483 100644
--- a/vm.c
+++ b/vm.c
@@ -2779,6 +2779,9 @@ static VALUE core_hash_merge_kwd(VALUE hash, VALUE kw);
static VALUE
core_hash_merge(VALUE hash, long argc, const VALUE *argv)
{
+ if (hash == rb_no_keyword_hash) {
+ hash = rb_hash_new();
+ }
Check_Type(hash, T_HASH);
VM_ASSERT(argc % 2 == 0);
rb_hash_bulk_insert(argc, argv, hash);
@@ -2790,23 +2793,14 @@ m_core_hash_merge_ptr(int argc, VALUE *argv, VALUE recv)
{
VALUE hash = argv[0];
- REWIND_CFP(core_hash_merge(hash, argc-1, argv+1));
+ REWIND_CFP(hash = core_hash_merge(hash, argc-1, argv+1));
return hash;
}
-static void
-kw_check_symbol(VALUE key)
-{
- if (!SYMBOL_P(key)) {
- rb_raise(rb_eTypeError, "hash key %+"PRIsVALUE" is not a Symbol",
- key);
- }
-}
static int
kwmerge_i(VALUE key, VALUE value, VALUE hash)
{
- kw_check_symbol(key);
rb_hash_aset(hash, key, value);
return ST_CONTINUE;
}
@@ -2821,6 +2815,8 @@ m_core_hash_merge_kwd(VALUE recv, VALUE hash, VALUE kw)
static VALUE
core_hash_merge_kwd(VALUE hash, VALUE kw)
{
+ if (RHASH_EMPTY_P(hash) && kw == rb_no_keyword_hash)
+ return rb_no_keyword_hash;
rb_hash_foreach(rb_to_hash_type(kw), kwmerge_i, hash);
return hash;
}