summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog8
-rw-r--r--error.c2
-rw-r--r--object.c5
-rw-r--r--test/ruby/test_object.rb8
4 files changed, 21 insertions, 2 deletions
diff --git a/ChangeLog b/ChangeLog
index d44d5c6c23..7e067a64ee 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -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>
* lib/net/http/generic_request.rb (encode_multipart_form_data): remove
diff --git a/error.c b/error.c
index da24505eb0..4b678d8957 100644
--- a/error.c
+++ b/error.c
@@ -1390,7 +1390,7 @@ syserr_eqq(VALUE self, VALUE exc)
*
* <em>raises the exception:</em>
*
- * TypeError: can't convert String into Integer
+ * TypeError: no implicit conversion of String into Integer
*
*/
diff --git a/object.c b/object.c
index 09b8040820..ba4f997b3a 100644
--- a/object.c
+++ b/object.c
@@ -2277,6 +2277,7 @@ static struct conv_method_tbl {
{"to_s", 0},
{NULL, 0}
};
+#define IMPLICIT_CONVERSIONS 7
static VALUE
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);
if (r == Qundef) {
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" :
val == Qtrue ? "true" :
val == Qfalse ? "false" :
diff --git a/test/ruby/test_object.rb b/test/ruby/test_object.rb
index 9f0e9bc5b2..9787525bce 100644
--- a/test/ruby/test_object.rb
+++ b/test/ruby/test_object.rb
@@ -885,4 +885,12 @@ class TestObject < Test::Unit::TestCase
assert_not_initialize_copy {st.new}
assert_not_initialize_copy {Time.now}
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