mirror of
https://github.com/mruby/mruby
synced 2026-06-08 16:11:16 +00:00
Merge pull request #1871 from ksss/numeric-plus
fix bug when `0 + other object`
This commit is contained in:
+1
-1
@@ -1131,10 +1131,10 @@ mrb_fixnum_plus(mrb_state *mrb, mrb_value x, mrb_value y)
|
||||
mrb_int a;
|
||||
|
||||
a = mrb_fixnum(x);
|
||||
if (a == 0) return y;
|
||||
if (mrb_fixnum_p(y)) {
|
||||
mrb_int b, c;
|
||||
|
||||
if (a == 0) return y;
|
||||
b = mrb_fixnum(y);
|
||||
c = a + b;
|
||||
if (((a < 0) ^ (b < 0)) == 0 && (a < 0) != (c < 0)) {
|
||||
|
||||
@@ -15,6 +15,9 @@ assert('Integer#+', '15.2.8.3.1') do
|
||||
|
||||
assert_equal 2, a
|
||||
assert_equal 2.0, b
|
||||
|
||||
assert_raise(TypeError){ 0+nil }
|
||||
assert_raise(TypeError){ 1+nil }
|
||||
end
|
||||
|
||||
assert('Integer#-', '15.2.8.3.2') do
|
||||
|
||||
Reference in New Issue
Block a user