summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorYukihiro "Matz" Matsumoto <[email protected]>2014-03-17 00:14:42 +0900
committerYukihiro "Matz" Matsumoto <[email protected]>2014-03-17 00:14:42 +0900
commite4ae3bf661a11dc22480619aac57c8a28b801cc9 (patch)
tree4e4a17c2db3558aa90da625ef218abc54388eef0
parent5140e27b5a970d717138fe0b15b20e345f7ea5f6 (diff)
parente9f3dca0f44003e0fe787101d47cd816393e7767 (diff)
downloadmruby-e4ae3bf661a11dc22480619aac57c8a28b801cc9.tar.gz
mruby-e4ae3bf661a11dc22480619aac57c8a28b801cc9.zip
Merge pull request #1871 from ksss/numeric-plus
fix bug when `0 + other object`
-rw-r--r--src/numeric.c2
-rw-r--r--test/t/integer.rb3
2 files changed, 4 insertions, 1 deletions
diff --git a/src/numeric.c b/src/numeric.c
index 066c5e154..b0b80c523 100644
--- a/src/numeric.c
+++ b/src/numeric.c
@@ -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)) {
diff --git a/test/t/integer.rb b/test/t/integer.rb
index 486224c85..66dd61c0b 100644
--- a/test/t/integer.rb
+++ b/test/t/integer.rb
@@ -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