Commit ffdef362 authored by Yukihiro "Matz" Matsumoto's avatar Yukihiro "Matz" Matsumoto

Merge pull request #1874 from ksss/float-plus

float + nil should be raise TypeError
parents 18bebd3a 0fab9d55
...@@ -1306,15 +1306,14 @@ num_cmp(mrb_state *mrb, mrb_value self) ...@@ -1306,15 +1306,14 @@ num_cmp(mrb_state *mrb, mrb_value self)
* and <code>other</code>. * and <code>other</code>.
*/ */
static mrb_value static mrb_value
flo_plus(mrb_state *mrb, mrb_value self) flo_plus(mrb_state *mrb, mrb_value x)
{ {
mrb_float x, y; mrb_value y;
x = mrb_float(self);
mrb_get_args(mrb, "f", &y);
return mrb_float_value(mrb, x + y); mrb_get_args(mrb, "o", &y);
return mrb_float_value(mrb, mrb_float(x) + mrb_to_flo(mrb, y));
} }
/* ------------------------------------------------------------------------*/ /* ------------------------------------------------------------------------*/
void void
mrb_init_numeric(mrb_state *mrb) mrb_init_numeric(mrb_state *mrb)
......
...@@ -15,6 +15,9 @@ assert('Float#+', '15.2.9.3.1') do ...@@ -15,6 +15,9 @@ assert('Float#+', '15.2.9.3.1') do
assert_float(3.123456789, a) assert_float(3.123456789, a)
assert_float(4.123456789, b) assert_float(4.123456789, b)
assert_raise(TypeError){ 0.0+nil }
assert_raise(TypeError){ 1.0+nil }
end end
assert('Float#-', '15.2.9.3.2') do assert('Float#-', '15.2.9.3.2') do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment