Repository navigation
Fix stack overflow when slicing a zipped Seq of unknown size from the end - #2311
Merged
Merged
Conversation
`zipWithFactory` set `__iterate` on the zipped Seq instead of `__iterateUncached`. That skipped the cache in `Seq#__iterate`, and `cacheResult()` did nothing because it checks for `__iterateUncached`. `slice` caches a Seq of unknown size before resolving a negative index, so `slice(-1)` or `takeLast(n)` on a zip of a Seq of unknown size recursed until "Maximum call stack size exceeded". Co-Authored-By: Claude Opus 5.5 <[email protected]>
Contributor
|
Thanks for your PRs around reverse |
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.
Slicing a zipped Seq of unknown size from the end overflows the stack:
takeLast(n),zipWithandzipAlldo the same.sliceFactorycallscacheResult()on a Seq of unknown size before resolving a negative index, then calls itself again.zipWithFactorysets__iterateon the zipped Seq instead of__iterateUncached.cacheResult()only does anything when__iterateUncachedexists, so the size stays unknown andsliceFactoryrecurses forever. With the rename,Seq#__iterateuses the cache andcacheResult()works.This doesn't overlap with #2308, which changes the reverse branch of
__iteratorUncachedin the same factory; the two merge cleanly and the tests pass together.The test in
__tests__/zip.tsfails onmainand passes with this change. The same code is on6.x.I used Claude Code to write this change.