ruby-changes:54581
From: nobu <ko1@a...>
Date: Sat, 12 Jan 2019 14:03:02 +0900 (JST)
Subject: [ruby-changes:54581] nobu:r66796 (trunk): No TypeError at nil if exception: false
nobu 2019-01-12 14:02:58 +0900 (Sat, 12 Jan 2019) New Revision: 66796 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=66796 Log: No TypeError at nil if exception: false [ruby-core:91021] [Bug #15525] Modified files: trunk/complex.c trunk/rational.c trunk/test/ruby/test_complex.rb trunk/test/ruby/test_rational.rb Index: rational.c =================================================================== --- rational.c (revision 66795) +++ rational.c (revision 66796) @@ -2559,8 +2559,10 @@ nurat_convert(VALUE klass, VALUE numv, V https://github.com/ruby/ruby/blob/trunk/rational.c#L2559 VALUE a1 = numv, a2 = denv; int state; - if (NIL_P(a1) || NIL_P(a2)) + if (NIL_P(a1) || NIL_P(a2)) { + if (!raise) return Qnil; rb_raise(rb_eTypeError, "can't convert nil into Rational"); + } if (RB_TYPE_P(a1, T_COMPLEX)) { if (k_exact_zero_p(RCOMPLEX(a1)->imag)) Index: complex.c =================================================================== --- complex.c (revision 66795) +++ complex.c (revision 66796) @@ -1943,8 +1943,10 @@ to_complex(VALUE val) https://github.com/ruby/ruby/blob/trunk/complex.c#L1943 static VALUE nucomp_convert(VALUE klass, VALUE a1, VALUE a2, int raise) { - if (NIL_P(a1) || NIL_P(a2)) + if (NIL_P(a1) || NIL_P(a2)) { + if (!raise) return Qnil; rb_raise(rb_eTypeError, "can't convert nil into Complex"); + } if (RB_TYPE_P(a1, T_STRING)) { a1 = string_to_c_strict(a1, raise); Index: test/ruby/test_complex.rb =================================================================== --- test/ruby/test_complex.rb (revision 66795) +++ test/ruby/test_complex.rb (revision 66796) @@ -866,9 +866,15 @@ class Complex_Test < Test::Unit::TestCas https://github.com/ruby/ruby/blob/trunk/test/ruby/test_complex.rb#L866 assert_equal(nil, Complex('5x', exception: false)) } assert_nothing_raised(ArgumentError){ + assert_equal(nil, Complex(nil, exception: false)) + } + assert_nothing_raised(ArgumentError){ assert_equal(nil, Complex(Object.new, exception: false)) } assert_nothing_raised(ArgumentError){ + assert_equal(nil, Complex(1, nil, exception: false)) + } + assert_nothing_raised(ArgumentError){ assert_equal(nil, Complex(1, Object.new, exception: false)) } Index: test/ruby/test_rational.rb =================================================================== --- test/ruby/test_rational.rb (revision 66795) +++ test/ruby/test_rational.rb (revision 66796) @@ -816,9 +816,15 @@ class Rational_Test < Test::Unit::TestCa https://github.com/ruby/ruby/blob/trunk/test/ruby/test_rational.rb#L816 assert_equal(nil, Rational("1/0", exception: false)) } assert_nothing_raised(TypeError) { + assert_equal(nil, Rational(nil, exception: false)) + } + assert_nothing_raised(TypeError) { assert_equal(nil, Rational(Object.new, exception: false)) } assert_nothing_raised(TypeError) { + assert_equal(nil, Rational(1, nil, exception: false)) + } + assert_nothing_raised(TypeError) { assert_equal(nil, Rational(1, Object.new, exception: false)) } -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/