
#15886: Spurious warning about incomplete pattern with PatternSynonyms -------------------------------------+------------------------------------- Reporter: selinger | Owner: (none) Type: bug | Status: closed Priority: normal | Milestone: 8.6.3 Component: Compiler | Version: 8.6.1 Resolution: invalid | Keywords: | PatternSynonyms, | PatternMatchWarnings Operating System: Linux | Architecture: x86_64 Type of failure: Incorrect | (amd64) error/warning at compile-time | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by RyanGlScott): * keywords: => PatternSynonyms, PatternMatchWarnings * status: new => closed * resolution: => invalid Comment: This is expected behavior. Refer to the [https://downloads.haskell.org/~ghc/8.4.1/docs/html/users_guide/glasgow_exts.... #complete-pragmas users' guide section] on `COMPLETE` sets:
The `COMPLETE` pragma is used to inform the pattern match checker that a certain set of patterns is complete and that any function which matches on all the specified patterns is total.
The most common usage of `COMPLETE pragmas` is with //Pattern synonyms//. On its own, the checker is very naive and assumes that any match involving a pattern synonym will fail. As a result, any pattern match on a pattern synonym is regarded as incomplete unless the user adds a catch-all case.
As this suggests, you need to declare a `COMPLETE` set for `X` in order for the coverage checker to reason about it. This variant of your program, for instance, does not emit any warnings when compiled with `-Wincomplete- patterns`: {{{#!hs {-# LANGUAGE ViewPatterns #-} {-# LANGUAGE PatternSynonyms #-} module Test where f :: Int -> Bool f (id -> a) = True pattern X a <- (id -> a) {-# COMPLETE X :: Int #-} g :: Int -> Bool g (X a) = True }}} -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/15886#comment:1 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler