mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* array.c (flatten): use rb_obj_class instead of rb_class_of
because rb_class_of may return a singleton class. [ruby-dev:49781] [Bug #12738] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56111 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
19f624541f
commit
1f8765bb2b
3 changed files with 25 additions and 1 deletions
|
@ -1,3 +1,9 @@
|
||||||
|
Thu Sep 8 17:47:18 2016 Kazuki Tsujimoto <kazuki@callcc.net>
|
||||||
|
|
||||||
|
* array.c (flatten): use rb_obj_class instead of rb_class_of
|
||||||
|
because rb_class_of may return a singleton class.
|
||||||
|
[ruby-dev:49781] [Bug #12738]
|
||||||
|
|
||||||
Thu Sep 8 17:40:15 2016 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
Thu Sep 8 17:40:15 2016 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||||
|
|
||||||
* tool/rbinstall.rb (gem): use the bindir of each gemspec instead
|
* tool/rbinstall.rb (gem): use the bindir of each gemspec instead
|
||||||
|
|
2
array.c
2
array.c
|
@ -4583,7 +4583,7 @@ flatten(VALUE ary, int level, int *modified)
|
||||||
|
|
||||||
st_free_table(memo);
|
st_free_table(memo);
|
||||||
|
|
||||||
RBASIC_SET_CLASS(result, rb_class_of(ary));
|
RBASIC_SET_CLASS(result, rb_obj_class(ary));
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -813,6 +813,15 @@ class TestArray < Test::Unit::TestCase
|
||||||
assert_nothing_raised(RuntimeError, bug10748) {a.flatten(1)}
|
assert_nothing_raised(RuntimeError, bug10748) {a.flatten(1)}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_flattern_singleton_class
|
||||||
|
bug12738 = '[ruby-dev:49781] [Bug #12738]'
|
||||||
|
a = [[0]]
|
||||||
|
class << a
|
||||||
|
def m; end
|
||||||
|
end
|
||||||
|
assert_raise(NoMethodError, bug12738) { a.flatten.m }
|
||||||
|
end
|
||||||
|
|
||||||
def test_flatten!
|
def test_flatten!
|
||||||
a1 = @cls[ 1, 2, 3]
|
a1 = @cls[ 1, 2, 3]
|
||||||
a2 = @cls[ 5, 6 ]
|
a2 = @cls[ 5, 6 ]
|
||||||
|
@ -850,6 +859,15 @@ class TestArray < Test::Unit::TestCase
|
||||||
assert_nothing_raised(RuntimeError, bug10748) {a.flatten!(1)}
|
assert_nothing_raised(RuntimeError, bug10748) {a.flatten!(1)}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_flattern_singleton_class!
|
||||||
|
bug12738 = '[ruby-dev:49781] [Bug #12738]'
|
||||||
|
a = [[0]]
|
||||||
|
class << a
|
||||||
|
def m; end
|
||||||
|
end
|
||||||
|
assert_nothing_raised(NameError, bug12738) { a.flatten!.m }
|
||||||
|
end
|
||||||
|
|
||||||
def test_flatten_with_callcc
|
def test_flatten_with_callcc
|
||||||
need_continuation
|
need_continuation
|
||||||
o = Object.new
|
o = Object.new
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue