Skip to content

Missing overlapping pattern warning for pattern with required constraint

Adding a required constraint to a pattern affects overlap checking:

{-# OPTIONS_GHC -Woverlapping-patterns -Wincomplete-patterns #-}
{-# LANGUAGE FlexibleContexts, PatternSynonyms #-} 

class C a where

pattern P1 :: C Int => Int
pattern P1 = 1

test :: C Int => Int -> Int
test i = case i of
  P1 -> 3
  P1 -> 7
  _  -> 11

This causes no warnings. Removing the required constraint to the pattern signature of P1 reinstates the expected warning:

    Pattern match is redundant
    In a case alternative: P1 -> ...

Note that this is not limited to pattern synonyms, as can be seen by inlining the pattern signature.
Note also that completeness checking is not affected (as can be seen by removing the catch-all case).

I saw a few tickets concerning overlap checking in particular in the context of insoluble constraints (e.g. #13766), but in this case it seems a shame to lose overlap checking. Is there some option I could switch on to enforce overlap checks?

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