GHC 9.6+: -Woverlapping-patterns triggers in compiled code, but not in GHCi
Consider this somewhat silly example (that is heavily minimized from a much larger piece of code in the wild):
{-# OPTIONS_GHC -Woverlapping-patterns #-}
module Bug where
import Data.Traversable
f :: () -> ()
f _ | (_, []) <- mapAccumL (\s a -> (s, a)) () []
= ()
| (_, _:_) <- mapAccumL (\s a -> (s, a)) () []
= ()
f _ = ()
The f _ = ()
equation is redundant, as the two mapAccumL
guards above it cover all possible cases. If you compile this program directly with GHC 9.6.2, it will warn you about this as expected:
$ ghc-9.6.2 Bug.hs -fforce-recomp
[1 of 1] Compiling Bug ( Bug.hs, Bug.o )
Bug.hs:11:1: warning: [GHC-53633] [-Woverlapping-patterns]
Pattern match is redundant
In an equation for ‘f’: f _ = ...
|
11 | f _ = ()
| ^^^^^^^
On the other hand, it will not warn you if you load the code into GHCi:
$ ghci-9.6 Bug.hs
GHCi, version 9.6.2: https://www.haskell.org/ghc/ :? for help
Loaded GHCi configuration from /home/ryanglscott/.ghci
[1 of 1] Compiling Bug ( Bug.hs, interpreted )
Ok, one module loaded.
This feels inconsistent.
Note that on older version of GHC (e.g., 9.4), no -Woverlapping-patterns
are given at all, regardless of whether you use GHC or GHCi.