1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* object.c: Improve error for failed implicit conversions [Bug #7539]

* error.c: Adapt rdoc

* test/ruby/test_object.rb: Test for above

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@38979 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
marcandre 2013-01-29 22:00:58 +00:00
parent 115a51f8ec
commit c34e9f23aa
4 changed files with 21 additions and 2 deletions

View file

@ -1,3 +1,11 @@
Wed Jan 30 07:00:16 2013 Marc-Andre Lafortune <ruby-core@marc-andre.ca>
* object.c: Improve error for failed implicit conversions [Bug #7539]
* error.c: Adapt rdoc
* test/ruby/test_object.rb: Test for above
Tue Jan 29 21:40:12 2013 Tanaka Akira <akr@fsij.org> Tue Jan 29 21:40:12 2013 Tanaka Akira <akr@fsij.org>
* lib/net/http/generic_request.rb (encode_multipart_form_data): remove * lib/net/http/generic_request.rb (encode_multipart_form_data): remove

View file

@ -1390,7 +1390,7 @@ syserr_eqq(VALUE self, VALUE exc)
* *
* <em>raises the exception:</em> * <em>raises the exception:</em>
* *
* TypeError: can't convert String into Integer * TypeError: no implicit conversion of String into Integer
* *
*/ */

View file

@ -2277,6 +2277,7 @@ static struct conv_method_tbl {
{"to_s", 0}, {"to_s", 0},
{NULL, 0} {NULL, 0}
}; };
#define IMPLICIT_CONVERSIONS 7
static VALUE static VALUE
convert_type(VALUE val, const char *tname, const char *method, int raise) convert_type(VALUE val, const char *tname, const char *method, int raise)
@ -2296,7 +2297,9 @@ convert_type(VALUE val, const char *tname, const char *method, int raise)
r = rb_check_funcall(val, m, 0, 0); r = rb_check_funcall(val, m, 0, 0);
if (r == Qundef) { if (r == Qundef) {
if (raise) { if (raise) {
rb_raise(rb_eTypeError, "can't convert %s into %s", rb_raise(rb_eTypeError, i < IMPLICIT_CONVERSIONS
? "no implicit conversion of %s into %s"
: "can't convert %s into %s",
NIL_P(val) ? "nil" : NIL_P(val) ? "nil" :
val == Qtrue ? "true" : val == Qtrue ? "true" :
val == Qfalse ? "false" : val == Qfalse ? "false" :

View file

@ -885,4 +885,12 @@ class TestObject < Test::Unit::TestCase
assert_not_initialize_copy {st.new} assert_not_initialize_copy {st.new}
assert_not_initialize_copy {Time.now} assert_not_initialize_copy {Time.now}
end end
def test_type_error_message
issue = "Bug #7539"
err = assert_raise(TypeError){ Integer([42]) }
assert_equal "can't convert Array into Integer", err.message, issue
err = assert_raise(TypeError){ [].first([42]) }
assert_equal 'no implicit conversion of Array into Integer', err.message, issue
end
end end