foldl on infinite list crashes GHCi
Summary
(It's somewhat similar to #23343 (closed).)
Steps to reproduce
I've reproduced it several times in a row, and I'm copying below from my terminal the last attempt. I just waited after the exception.
$ ghci
Loaded package environment from /home/enrico/.ghc/x86_64-linux-9.4.8/environments/default
GHCi, version 9.4.8: https://www.haskell.org/ghc/ :? for help
Loaded GHCi configuration from /home/enrico/myconfigfiles/HOME/#ghci
λ> take 10 $ foldl (flip (:)) [] [1..]
*** Exception: heap overflow
λ>
λ>
λ>
panic! (the 'impossible' happened)
GHC version 9.4.8:
heap overflow
Please report this as a GHC bug: https://www.haskell.org/ghc/reportabug
Expected behavior
The exception is fine, but it shouldn't crash GHC.
Environment
- GHC version used: 9.4.8
Optional:
- Operating System: up-to-date ArchLinux
- System Architecture: 64bits