From 421a73f51a39ff6829f9715b423a928782ec8ec3 Mon Sep 17 00:00:00 2001 From: nobu Date: Thu, 15 Mar 2018 00:12:17 +0000 Subject: vm.c: refined error message * vm.c (kw_check_symbol): refined the error message for non-symbol key. [Feature #14603] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62752 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- vm.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/vm.c b/vm.c index fcb6f9a8e4..1a57f2c6d1 100644 --- a/vm.c +++ b/vm.c @@ -2742,10 +2742,18 @@ m_core_hash_merge_ptr(int argc, VALUE *argv, VALUE recv) 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) { - Check_Type(key, T_SYMBOL); + kw_check_symbol(key); rb_hash_aset(hash, key, value); return ST_CONTINUE; } @@ -2753,7 +2761,7 @@ kwmerge_i(VALUE key, VALUE value, VALUE hash) static int kwcheck_i(VALUE key, VALUE value, VALUE hash) { - Check_Type(key, T_SYMBOL); + kw_check_symbol(key); return ST_CONTINUE; } -- cgit v1.2.3