diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2015-12-12 09:52:36 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2015-12-12 09:52:36 +0000 |
commit | 975c414b91224ec7144451982a4433a5442be6fc (patch) | |
tree | d78e9ee580e2f49bcae9775d43cf2532de244f2c /object.c | |
parent | 2b988c36bea29718b1518c0c486891634db039d4 (diff) | |
download | ruby-975c414b91224ec7144451982a4433a5442be6fc.tar.gz |
object.c: raise TypeError
* object.c (rb_obj_dig): raise TypeError if an element does not
have #dig method. [ruby-core:71798] [Bug #11762]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@53058 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'object.c')
-rw-r--r-- | object.c | 13 |
1 files changed, 12 insertions, 1 deletions
@@ -3169,12 +3169,22 @@ dig_basic_p(VALUE obj, struct dig_method *cache) return cache->basic; } +static void +no_dig_method(int found, VALUE recv, ID mid, int argc, const VALUE *argv, VALUE data) +{ + if (!found) { + rb_raise(rb_eTypeError, "%"PRIsVALUE" does not have #dig method", + CLASS_OF(data)); + } +} + VALUE rb_obj_dig(int argc, VALUE *argv, VALUE obj, VALUE notfound) { struct dig_method hash = {Qnil}, ary = {Qnil}, strt = {Qnil}; for (; argc > 0; ++argv, --argc) { + if (NIL_P(obj)) return notfound; if (!SPECIAL_CONST_P(obj)) { switch (BUILTIN_TYPE(obj)) { case T_HASH: @@ -3197,7 +3207,8 @@ rb_obj_dig(int argc, VALUE *argv, VALUE obj, VALUE notfound) break; } } - return rb_check_funcall_default(obj, id_dig, argc, argv, notfound); + return rb_check_funcall_with_hook(obj, id_dig, argc, argv, + no_dig_method, obj); } return obj; } |