aboutsummaryrefslogtreecommitdiffstats
path: root/object.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-12-12 09:52:36 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-12-12 09:52:36 +0000
commit3ac72e471401e03ec66159229067a15fe9a47874 (patch)
treed78e9ee580e2f49bcae9775d43cf2532de244f2c /object.c
parentd6a698dd42ee1231db85e2667b185afb32e73c4a (diff)
downloadruby-3ac72e471401e03ec66159229067a15fe9a47874.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.c13
1 files changed, 12 insertions, 1 deletions
diff --git a/object.c b/object.c
index 1f73cb401b..3111701c58 100644
--- a/object.c
+++ b/object.c
@@ -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;
}