Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ReadOnly Array flatMap stack overflow #2048

Closed
joepjoosten opened this issue Feb 5, 2024 · 3 comments · Fixed by #2057
Closed

ReadOnly Array flatMap stack overflow #2048

joepjoosten opened this issue Feb 5, 2024 · 3 comments · Fixed by #2057
Labels
bug Something isn't working

Comments

@joepjoosten
Copy link
Contributor

What version of Effect is running?

2.2.3

What steps can reproduce the bug?

import { pipe } from 'effect/Function';
import * as RA from 'effect/ReadonlyArray';

const arr: number[][] = [[]];
for (let i = 0; i < 135000; i++) {
  arr[0].push(i);
}

const flattened = pipe(
  arr,
  RA.flatMap((x) => x),
);

console.log(flattened.length);

What is the expected behavior?

135000

What do you see instead?

RangeError: Maximum call stack size exceeded
at ....../node_modules/.pnpm/effect@2.2.3/node_modules/effect/dist/cjs/ReadonlyArray.js:1046:9

Additional information

https://stackoverflow.com/questions/61740599/rangeerror-maximum-call-stack-size-exceeded-with-array-push

@joepjoosten joepjoosten added the bug Something isn't working label Feb 5, 2024
@joepjoosten
Copy link
Contributor Author

Possibly also a problem in other places where spread operator is used...

@joepjoosten
Copy link
Contributor Author

joepjoosten commented Feb 5, 2024

I find 6 other places where this potentially also is a problem:
https://github.com/search?q=repo%3AEffect-TS%2Feffect%20push(...&type=code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
1 participant