ApplicativeDo causes the wrong line to be reported in non-exhaustive pattern error messages
Summary
With ApplicativeDo
on, some programs (such as a test that crashed yesterday) that are Applicative in structure can get desugared to Applicative, and the source of non-exhaustive pattern error messages gets mixed up.
Steps to reproduce
Save this in Test.hs
:
main = do
let x = ()
res2 <- pure ()
~(Just res1) <- seq x (pure $ Nothing @())
print res1
print res2
pure ()
Then:
[nix-shell:~/dev/nixpkgs]$ runhaskell Test.hs
Test.hs: Test.hs:4:3-44: Non-exhaustive patterns in Just res1
[nix-shell:~/dev/nixpkgs]$ runhaskell -XApplicativeDo Test.hs
Test.hs: Test.hs:2:3-12: Non-exhaustive patterns in Just res1
Line 2 is incorrectly reported as the cause in the case of ApplicativeDo (which in the case of the test I was hacking on, was actually another irrefutable pattern that was actually fine, so I was absolutely baffled).
Expected behavior
Both cases of -XApplicativeDo
and not should report the same error location.
Environment
- GHC version used: 9.4.3
Optional:
- Operating System: macOS
- System Architecture: aarch64