From 7b974232fd5458b96996dfd7e3b5420aadb46b01 Mon Sep 17 00:00:00 2001 From: tadf Date: Thu, 18 Jun 2009 13:41:44 +0000 Subject: * rational.c (nurat_s_convert): calls to_r when the given argument is non-integer. * rational.c (nurat_s_convert): raises TypeError when the given argument is nil. git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@23735 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- complex.c | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'complex.c') diff --git a/complex.c b/complex.c index 0e9a17b7a..630f25b1e 100644 --- a/complex.c +++ b/complex.c @@ -1248,6 +1248,9 @@ nucomp_s_convert(int argc, VALUE *argv, VALUE klass) rb_scan_args(argc, argv, "11", &a1, &a2); + if (NIL_P(a1) || (argc == 2 && NIL_P(a2))) + rb_raise(rb_eTypeError, "can't convert nil into Complex"); + backref = rb_backref_get(); rb_match_busy(backref); @@ -1302,6 +1305,9 @@ nucomp_s_convert(int argc, VALUE *argv, VALUE klass) if (argc == 1) { if (k_numeric_p(a1) && !f_real_p(a1)) return a1; + /* expect raise exception for consistency */ + if (!k_numeric_p(a1)) + return rb_convert_type(a1, T_COMPLEX, "Complex", "to_c"); } else { if ((k_numeric_p(a1) && k_numeric_p(a2)) && -- cgit