Skip to content

Different -Woverlapping-patterns warnings in GHCi versus compiled code

In the following code:

{-# OPTIONS_GHC -Woverlapping-patterns #-}
module Bug where

f :: Int
f | id (id True)
  = 1

  | id (id True)
  , True
  = 2

  | otherwise
  = 3

The second guard is definitely redundant, and GHC 9.0.1 and later recognize this when compiled normally:

$ ghc-9.0.1 Bug.hs -fforce-recomp
[1 of 1] Compiling Bug              ( Bug.hs, Bug.o )

Bug.hs:8:5: warning: [-Woverlapping-patterns]
    Pattern match is redundant
    In an equation for ‘f’: f | id (id True), True = ...
  |
8 |   | id (id True)
  |     ^^^^^^^^^^^^

When loaded into GHCi, however, the warning does not occur for some reason:

$ ghci-9.0.1 Bug.hs
GHCi, version 9.0.1: https://www.haskell.org/ghc/  :? for help
Loaded GHCi configuration from /home/rscott/.ghci
[1 of 1] Compiling Bug              ( Bug.hs, interpreted )
Ok, one module loaded.

I would expect both modes to produce the same warnings.

cc @sgraf812

To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information