aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorktsj <ktsj@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-09-08 08:56:30 +0000
committerktsj <ktsj@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-09-08 08:56:30 +0000
commitec4a0e83b33ed4acfdd7673ca5e8c25b6075f735 (patch)
treeff16188ebb98de5f81627826b6707637908c8e21
parent29673bdcbd648a42f5afd1c38c84595354cb30f5 (diff)
downloadruby-ec4a0e83b33ed4acfdd7673ca5e8c25b6075f735.tar.gz
* 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
-rw-r--r--ChangeLog6
-rw-r--r--array.c2
-rw-r--r--test/ruby/test_array.rb18
3 files changed, 25 insertions, 1 deletions
diff --git a/ChangeLog b/ChangeLog
index 39eb848292..3fe44c32d6 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -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>
* tool/rbinstall.rb (gem): use the bindir of each gemspec instead
diff --git a/array.c b/array.c
index 65fd0b6268..4e60177121 100644
--- a/array.c
+++ b/array.c
@@ -4583,7 +4583,7 @@ flatten(VALUE ary, int level, int *modified)
st_free_table(memo);
- RBASIC_SET_CLASS(result, rb_class_of(ary));
+ RBASIC_SET_CLASS(result, rb_obj_class(ary));
return result;
}
diff --git a/test/ruby/test_array.rb b/test/ruby/test_array.rb
index addce0d9ba..a19e22aab4 100644
--- a/test/ruby/test_array.rb
+++ b/test/ruby/test_array.rb
@@ -813,6 +813,15 @@ class TestArray < Test::Unit::TestCase
assert_nothing_raised(RuntimeError, bug10748) {a.flatten(1)}
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!
a1 = @cls[ 1, 2, 3]
a2 = @cls[ 5, 6 ]
@@ -850,6 +859,15 @@ class TestArray < Test::Unit::TestCase
assert_nothing_raised(RuntimeError, bug10748) {a.flatten!(1)}
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
need_continuation
o = Object.new