Pattern-match checker suggests ill-typed match on pattern synonym
Consider
{-# LANGUAGE PatternSynonyms #-}
{-# LANGUAGE ViewPatterns #-}
module Lib where
class C f where
foo :: f a -> ()
pattern P :: C f => f a
pattern P <- (foo -> ())
{-# COMPLETE P #-}
class D f where
bar :: f a -> ()
pattern Q :: D f => f a
pattern Q <- (bar -> ())
g :: D f => f a -> ()
g Q = () -- Should warn! The sig shouldn't apply in a polymorphic context.
This emits the warning
test.hs:18:1: warning: [-Wincomplete-patterns]
Pattern match(es) are non-exhaustive
In an equation for ‘g’: Patterns of type ‘f a’ not matched: P
|
18 | g Q = () -- Should warn! The sig shouldn't apply in a polymorphic context.
| ^^^^^^^^
Confusingly, this suggests P
as a constructor to match, which doesn't even match the pattern match result type D f => f a
. Clearly, we are too liberal from which COMPLETE sets we suggest ConLikes to the user.