diff options
author | naruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2008-08-29 09:37:00 +0000 |
---|---|---|
committer | naruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2008-08-29 09:37:00 +0000 |
commit | 889acc818531840818cb2809bdaf2c25285b16f5 (patch) | |
tree | f8be6277c27122da8a73dd96f19003f32fd83d05 /encoding.c | |
parent | 56c3432476f750c02822bd0e99d74a6035cf7c43 (diff) | |
download | ruby-889acc818531840818cb2809bdaf2c25285b16f5.tar.gz |
* encoding.c (enc_compatible_p): raise TypeError when argument is not
String nor Regexp.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@18920 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'encoding.c')
-rw-r--r-- | encoding.c | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/encoding.c b/encoding.c index 291070dd19..21614245ae 100644 --- a/encoding.c +++ b/encoding.c @@ -880,8 +880,14 @@ enc_compatible_p(VALUE klass, VALUE str1, VALUE str2) { rb_encoding *enc; - if (enc_check_encoding(str1) > 0 || enc_check_encoding(str2) > 0) - rb_raise(rb_eTypeError, "wrong argument type Encoding (expected String)"); + if (BUILTIN_TYPE(str1) != T_STRING && BUILTIN_TYPE(str1) != T_REGEXP) { + rb_raise(rb_eTypeError, "wrong argument type %s (expected String or Regexp)", + rb_obj_classname(str1)); + } + if (BUILTIN_TYPE(str2) != T_STRING && BUILTIN_TYPE(str2) != T_REGEXP) { + rb_raise(rb_eTypeError, "wrong argument type %s (expected String or Regexp)", + rb_obj_classname(str2)); + } if (!enc_capable(str1)) return Qnil; if (!enc_capable(str2)) return Qnil; enc = rb_enc_compatible(str1, str2); |