mirror of
https://github.com/ruby/ruby.git
synced 2026-10-28 16:36:20 +08:00
Avoid freezing nested array in Array#flatten!
This commit is contained in:
1 parent
19db053a7d
commit
ed55edaa9e
2 files changed
+7
-1
Notes:
git
2026-08-28 05:47:43 +00:00
No files matched your search
@@ -6916,7 +6916,7 @@ rb_ary_flatten_bang(int argc, VALUE *argv, VALUE ary)
|
||||
}
|
||||
}
|
||||
|
||||
if (!(mod = ARY_EMBED_P(result) && result != child)) rb_ary_freeze(result);
|
||||
if (result != child && !(mod = ARY_EMBED_P(result))) rb_ary_freeze(result);
|
||||
rb_ary_replace(ary, result);
|
||||
if (mod) ARY_SET_EMBED_LEN(result, 0);
|
||||
|
||||
|
||||
@@ -1018,6 +1018,12 @@ class TestArray < Test::Unit::TestCase
|
||||
assert_equal(@cls[1, 2, 3, 4, 5, 6], a5)
|
||||
end
|
||||
|
||||
def test_flatten_bang_does_not_freeze_nested_array
|
||||
child = []
|
||||
[child].flatten!
|
||||
assert_not_predicate(child, :frozen?)
|
||||
end
|
||||
|
||||
def test_flatten_empty!
|
||||
assert_nil(@cls[].flatten!)
|
||||
assert_equal(@cls[],
|
||||
|
||||
Reference in new issue
Block a user