From 16c6984bb97409029e213154ac4f633ae04af3d8 Mon Sep 17 00:00:00 2001 From: Yusuke Endoh Date: Mon, 18 Mar 2019 14:25:47 +0900 Subject: Separate keyword arguments from positional arguments And, allow non-symbol keys as a keyword arugment --- vm.c | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) (limited to 'vm.c') 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; } -- cgit v1.2.3