mirror of
https://github.com/mruby/mruby
synced 2026-06-08 16:11:16 +00:00
Merge pull request #1874 from ksss/float-plus
float + nil should be raise TypeError
This commit is contained in:
+5
-6
@@ -1306,15 +1306,14 @@ num_cmp(mrb_state *mrb, mrb_value self)
|
||||
* and <code>other</code>.
|
||||
*/
|
||||
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
|
||||
mrb_init_numeric(mrb_state *mrb)
|
||||
|
||||
@@ -15,6 +15,9 @@ assert('Float#+', '15.2.9.3.1') do
|
||||
|
||||
assert_float(3.123456789, a)
|
||||
assert_float(4.123456789, b)
|
||||
|
||||
assert_raise(TypeError){ 0.0+nil }
|
||||
assert_raise(TypeError){ 1.0+nil }
|
||||
end
|
||||
|
||||
assert('Float#-', '15.2.9.3.2') do
|
||||
|
||||
Reference in New Issue
Block a user