Project

General

Profile

Actions

Bug #22529

closed

Array#fill should respect frozenness from yields

Bug #22529: Array#fill should respect frozenness from yields
1

Added by tenderlovemaking (Aaron Patterson) 9 days ago. Updated 6 days ago.

Status:
Closed
Assignee:
-
Target version:
-
ruby -v:
ruby 4.0.9 (2026-10-23 revision 3e93b23afc) +PRISM [arm64-darwin25]
[ruby-core:127395]

Description

Array#fill yields to a block, and the array could get frozen in the block, so we need to check for it.

I expect the following program to raise an exception, but instead the array is mutated:

a = [1, 2, 3]
a.fill { a.freeze; 9 }
p a

Updated by tenderlovemaking (Aaron Patterson) 9 days ago Actions #2

  • Status changed from Open to Closed

Applied in changeset git|dd0ff240523781569ade1d438e16df2d381070aa.


Check array modifiability in Array#fill (#19821)

Array#fill yields to a block and the block code may freeze the array.
We need to check when iterating otherwise we'll end up mutating a frozen
array

[Bug #22529]

Updated by jhawthorn (John Hawthorn) 9 days ago Actions #3 [ruby-core:127410]

  • Backport changed from 3.3: UNKNOWN, 3.4: UNKNOWN, 4.0: UNKNOWN to 3.3: UNKNOWN, 3.4: UNKNOWN, 4.0: REQUIRED

Updated by jhawthorn (John Hawthorn) 6 days ago Actions #4

  • Backport changed from 3.3: UNKNOWN, 3.4: UNKNOWN, 4.0: REQUIRED to 3.3: UNKNOWN, 3.4: UNKNOWN, 4.0: DONE
Actions

Also available in: PDF Atom