From 0cb1a2b81232b5a64242fc6899d72be22b35495f Mon Sep 17 00:00:00 2001 From: mrkn Date: Tue, 6 Dec 2016 12:54:19 +0000 Subject: [PATCH] numeric.c: fix exception message for nil rounding * numeric.c (rb_num_get_rounding_option): fix exception message for the case of nil rounding mode. * test_float.rb: add an assertion for the above change. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57000 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- numeric.c | 5 ++++- test/ruby/test_float.rb | 3 +++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/numeric.c b/numeric.c index 74771cba6f..74ee5d136a 100644 --- a/numeric.c +++ b/numeric.c @@ -243,7 +243,10 @@ rb_num_get_rounding_option(VALUE opts) break; } invalid: - rb_raise(rb_eArgError, "invalid rounding mode: % "PRIsVALUE, rounding); + if (NIL_P(rounding)) + rb_raise(rb_eArgError, "invalid rounding mode: nil"); + else + rb_raise(rb_eArgError, "invalid rounding mode: % "PRIsVALUE, rounding); } noopt: return RUBY_NUM_ROUND_DEFAULT; diff --git a/test/ruby/test_float.rb b/test/ruby/test_float.rb index aed387029e..eccc86740a 100644 --- a/test/ruby/test_float.rb +++ b/test/ruby/test_float.rb @@ -723,6 +723,9 @@ class TestFloat < Test::Unit::TestCase end def test_round_half_invalid + assert_raise_with_message(ArgumentError, /nil/) { + 1.0.round(half: nil) + } assert_raise_with_message(ArgumentError, /xxx/) { 1.0.round(half: "\0xxx") }