diff options
-rw-r--r-- | ChangeLog | 5 | ||||
-rw-r--r-- | enum.c | 3 | ||||
-rw-r--r-- | test/ruby/test_enum.rb | 12 |
3 files changed, 19 insertions, 1 deletions
@@ -1,3 +1,8 @@ +Tue Mar 15 21:38:28 2016 Tanaka Akira <akr@fsij.org> + + * enum.c (enum_inject): Consider redefinition of Fixnum#+. + [ruby-dev:49510] [Bug#12178] Reported by usa. + Tue Mar 15 20:32:57 2016 Tanaka Akira <akr@fsij.org> * enum.c (enum_inject): Implement the specialized code for :+ operator @@ -719,7 +719,8 @@ enum_inject(int argc, VALUE *argv, VALUE obj) i = 0; } id = SYM2ID(op); - if (id == idPLUS && FIXNUM_P(v)) { + if (id == idPLUS && FIXNUM_P(v) && + rb_method_basic_definition_p(rb_cFixnum, idPLUS)) { long n = FIX2LONG(v); while (i < RARRAY_LEN(obj)) { VALUE e = RARRAY_AREF(obj, i); diff --git a/test/ruby/test_enum.rb b/test/ruby/test_enum.rb index 6162830b69..3dfbd26929 100644 --- a/test/ruby/test_enum.rb +++ b/test/ruby/test_enum.rb @@ -184,6 +184,18 @@ class TestEnumerable < Test::Unit::TestCase assert_equal(nil, @empty.inject() {9}) end + def test_inject_array_plus + assert_separately([], <<-"end;") + class Fixnum + undef :+ + def +(x) + 0 + end + end + assert_equal(0, [1,2,3].inject(:+), "[ruby-dev:49510] [Bug#12178]") + end; + end + def test_partition assert_equal([[1, 3, 1], [2, 2]], @obj.partition {|x| x % 2 == 1 }) cond = ->(x, i) { x % 2 == 1 } |