Repository navigation
Array: #[]= auto-grow + range/subclass assign, values_at ranges, dig/product/insert/rotate/flatten to_int (MRI 4.0.6) - #538
Merged
Conversation
…nsert/rotate to_int Array#[]= now auto-grows (nil-padding the gap) when a single index is at or beyond the end, matching MRI, instead of raising IndexError. The negative index and negative start/length errors now carry MRI's exact "index N too small for array; minimum: -M" message. The Range form accepts a Range subclass and coerces non-Integer endpoints via #to_int, and a begin at/beyond the end pads rather than raising RangeError. Multi-element (range and start,length) sets coerce a non-Array rhs through #to_ary and splice an Array subclass element-by-element; the return value is always the raw rhs. Array#values_at accepts Range arguments (including subclasses, #to_int endpoints, beginless/endless), padding out-of-bounds positions with nil and raising RangeError only for a begin still negative after normalisation. Array#insert, #rotate and #rotate! coerce their index/count via #to_int (so a Float or #to_int object works) rather than requiring an Integer. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
…h #to_int
Array#dig now digs into the extracted value by calling its own #dig with the
remaining keys (so an overridden or mocked #dig is honoured), raises
ArgumentError with no keys, and raises TypeError ("X does not have #dig
method") for a nested value that has no #dig — matching MRI.
Array#product accepts a block (yielding each combination and returning the
receiver) and coerces its arguments via #to_ary.
Array#flatten/#flatten! coerce the depth argument via #to_int (a nil depth is
unbounded).
Adds array_mutator_residuals_test.go covering the new #[]=/#values_at/#insert/
#rotate/#dig/#product/#flatten branches, and repoints the old TestArrayErrors
case that assumed #[]= raised on an out-of-range index (MRI auto-grows).
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
…clamp branches Refactors Array#dig to extract its first element inline and share the continuation with Hash#dig via a new digRest helper, removing the unreachable type-switch arms the earlier send-based recursion left behind. Adds tests for the two Array#[]= Range negative-length clamps (endless begin-beyond-end and an inverted range) and for Hash#dig's hit/miss/nested/arity paths, so every branch of the changed functions is exercised. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
tannevaled
added a commit
that referenced
this pull request
Sep 1, 2026
Locks in #535 (String methods: index/casecmp/chomp/gsub/scan/tr/... ~+110), #536 (IO/StringIO reader+writer), #538 (Array#[]= auto-grow + mutators), #539 (Range + Comparable), #540 (Struct + Data), #541 (Time). Measured 17983 passing on the pinned corpus, up from 17654. Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Advances MRI-Ruby-4.0.6 conformance for the Array mutator/index cluster.
Fixes
Array#[]=— single-index assignment at or beyond the end now auto-grows, nil-padding the gap (was:IndexError), matching MRI (a=[]; a[1]=14 #=> [nil, 14]). The(start,length)and Range forms pad beyond the end; a Range subclass and non-Integer (#to_int) endpoints are accepted; a multi-element rhs is coerced via#to_aryand an Array subclass is spliced element-by-element; the return value is always the raw rhs. Negative-index / negative-start / RangeError diagnostics now carry MRI's exact messages (index -5 too small for array; minimum: -3).Array#values_at— accepts Range arguments (subclasses,#to_intendpoints, beginless/endless, exclusive), padding out-of-bounds positions with nil and raisingRangeErroronly for a begin still negative after normalisation.Array#insert/#rotate/#rotate!— coerce the index/count via#to_int(so a Float or#to_intobject works).Array#dig— digs into the extracted value by calling its own#dig(an overridden/mocked#digis honoured), raisesArgumentErrorwith no keys, and raisesTypeErrorfor a nested value with no#dig.Array#product— accepts a block (yields each combination, returns the receiver) and coerces arguments via#to_ary.Array#flatten/#flatten!— coerce the depth argument via#to_int(a nil depth is unbounded).ruby/spec deltas (core/array)
No regressions in the Array equality/membership specs (equal_value/eql/uniq/comparison unchanged); those functions were left untouched.
Remaining (out of scope of this cluster)
filland severalflattenfailures are a spec-harnessbefore :allinstance-variable limitation (@never_passedresolves to nil) and a shared#to_ary-via-method_missingcoercion gap (rb_check_funcallsemantics) — not Array-mutator bugs.Tests:
internal/vm/array_mutator_residuals_test.gocovers the new branches; the oldTestArrayErrorscase that assumed#[]=raised on an out-of-range index was repointed (MRI auto-grows).🤖 Generated with Claude Code