[GHC] #15886: Spurious warning about incomplete pattern with PatternSynonyms
GHC
ghc-devs at haskell.org
Sat Nov 10 16:13:50 UTC 2018
#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: |
-------------------------------------+-------------------------------------
Comment (by RyanGlScott):
The rationale for requiring `COMPLETE` signatures to coverage-check
pattern synonyms can be found in
[https://ghc.haskell.org/trac/ghc/wiki/PatternSynonyms/CompleteSigs?version=15
the corresponding GHC wiki page]:
> The exhaustiveness checker currently chokes on pattern synonyms.
> They are marked as always fallible patterns which means that we must
also always include a catch-all case in order to avoid a warning.
>
> {{{#!hs
> data A = A
>
> pattern :: A
> pattern P = A
>
> foo :: A -> A
> foo P = A
> }}}
>
> leads to the warning that pattern matches for `foo` are non-exhaustive.
>
> {{{
> simpletest.hs:7:1: warning: [-Wincomplete-patterns]
> Pattern match(es) are non-exhaustive
> In an equation for ‘foo’: Patterns not matched: _
> }}}
>
> Inspecting the definition of `P` we can see that the matches for `foo`
are indeed exhaustive as `A` is a unary data type but the pattern match
checker does not make use of this information.
>
> And neither should it! Pattern synonyms are a means of *abstraction*, if
the exhaustiveness checker could look through a definition then the
implementation of `P` would leak into error messages.
> We want users to be able to replace bona-fide data constructors with
pattern synonyms without consumers noticing.
> To that end, we allow users to specify a complete set of pattern
synonyms in order to sate the pattern match checker. If a complete pragma
is not provided then we keep the same behaviour as in previous releases.
--
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/15886#comment:3>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler
More information about the ghc-tickets
mailing list