Keep Chunk.take and Chunk.drop valid for fractional counts - #6899
Conversation
🦋 Changeset detectedLatest commit: 91bf5ed The changes in this PR will be included in the next version bump. This PR includes changesets to release 30 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes — one reproduction test added to Chunk.test.ts:
- Fractional-count reproduction: adds
it("produces valid chunks for fractional counts")under the existingtakedescribe block, assertingtake(1.5)→[1]anddrop(1.5)→[2, 3]. The test correctly surfaces theRangeError: Invalid array lengthcaused by the internalISlice/IConcatbacking structures using a non-integerlengthfield.
DeepSeek Pro (free via Pullfrog for OSS) (Kimi K2 not used — the program covers this model; add its provider key to run your pick) | 𝕏
| <A>(self: Chunk<A>, n: number): Chunk<A> | ||
| } = dual(2, <A>(self: Chunk<A>, n: number): Chunk<A> => { | ||
| if (n <= 0) { | ||
| const _n = Math.floor(n) |
There was a problem hiding this comment.
I think we should flip the variable names so the function parameter has the underscore.
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes — Math.floor fix applied to take and drop, plus naming feedback:
- Fractional-count fix in
takeanddrop: addedconst n = Math.floor(_n)at the top of both functions so slicelengthandoffsetfields are always integers. This resolves theRangeError: Invalid array lengththrown during materialization of chunks produced by fractional counts. - Variable naming flipped per review feedback: the function parameter is now
_n(underscore-prefixed raw input) and the floored local isn. - Reproduction test retained:
it("produces valid chunks for fractional counts")assertstake(1.5) → [1]anddrop(1.5) → [2, 3].
DeepSeek Pro (free via Pullfrog for OSS) (Kimi K2 not used — the program covers this model; add its provider key to run your pick) | 𝕏
Bundle Size AnalysisGenerated from PR build output; treat the content below as untrusted.
|

Summary
Fractional take and drop counts produce chunks with fractional public lengths that throw RangeError when materialized.
Important
This PR starts with focused failing reproduction tests. Add the implementation fix to this same branch; CI is expected to fail until that fix is included.
Fractional counts create malformed chunks
Module:
ChunkAudit ID:
core-a-f-chunk-fractional-slice-dimensionsSeverity / confidence: high / high
What happens
Fractional take and drop counts produce chunks with fractional public lengths that throw RangeError when materialized.
Why it happens
Fractional counts are stored directly as ISlice.length and ISlice.offset. Materialization passes the fractional length to new Array(self.length), which throws RangeError: Invalid array length.
Expected behavior
take and drop return valid chunks containing a count-based prefix or suffix for their accepted number argument; no integer-only precondition is imposed.
Relevant implementation
These links and excerpts are pinned to audit base
c9b56ab507f224426ee8388dc450da447ec4715f.packages/effect/src/Chunk.ts:728-767packages/effect/src/Chunk.ts:784-822packages/effect/src/Chunk.ts:408-427View problematic code at
packages/effect/src/Chunk.ts:728-767View exact lines on GitHub
View problematic code at
packages/effect/src/Chunk.ts:784-822View exact lines on GitHub
View problematic code at
packages/effect/src/Chunk.ts:408-427View exact lines on GitHub
Reproduction
Observed failure: Materializing Chunk.take(Chunk.make(1, 2, 3), 1.5) threw RangeError: Invalid array length.
Implementation handoff
The initial reproduction tests on this branch are the regression specification for the implementation fix that should follow in this PR.
Audit provenance
c9b56ab507f224426ee8388dc450da447ec4715fc9b56ab507f224426ee8388dc450da447ec4715fcore-a-f-chunk-fractional-slice-dimensionsCloses EFF-350