diff options
author | Yusuke Endoh <mame@ruby-lang.org> | 2019-03-18 14:25:47 +0900 |
---|---|---|
committer | Jeremy Evans <code@jeremyevans.net> | 2019-08-30 12:39:31 -0700 |
commit | 16c6984bb97409029e213154ac4f633ae04af3d8 (patch) | |
tree | 53839e4d596e4016320097530ff5d7fcf19d11e6 /vm.c | |
parent | b0a291f6f6a5834fd84807eb48be906ade429871 (diff) |
Separate keyword arguments from positional arguments
And, allow non-symbol keys as a keyword arugment
Notes
Notes:
Merged: https://github.com/ruby/ruby/pull/2395
Diffstat (limited to 'vm.c')
-rw-r--r-- | vm.c | 16 |
1 files changed, 6 insertions, 10 deletions
@@ -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; } |