Avoid freezing nested array in Array#flatten!

This commit is contained in:
ydah authored and Nobuyoshi Nakada committed 2026-08-28 14:47:11 +09:00
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

+1 -1
View File
@@ -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);
+6
View File
@@ -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[],