Incorrect non-exhaustive pattern warning with PatternSynonyms
{-# language PatternSynonyms #-}
{-# language ViewPatterns #-}
{-# language TypeFamilies #-}
module Bug where
newtype GenLocated e = L e
newtype WithSourceText a = WithSourceText a
type StringLiteral = WithSourceText String
{-# COMPLETE StringLiteral #-}
pattern StringLiteral sl_s = WithSourceText sl_s
type family SrcSpanLess a
class HasSrcSpan a where
decomposeSrcSpan :: a -> GenLocated (SrcSpanLess a)
type instance SrcSpanLess (GenLocated e) = e
instance HasSrcSpan (GenLocated a) where
decomposeSrcSpan = id
bug :: GenLocated StringLiteral -> String
bug (decomposeSrcSpan->L (StringLiteral s)) = s
workaround :: GenLocated StringLiteral -> String
workaround (decomposeSrcSpan->L sl) = s
where StringLiteral s = sl
$ ghci -Wincomplete-patterns Bug.hs
GHCi, version 8.7.20190103: https://www.haskell.org/ghc/ :? for help
Loaded GHCi configuration from /home/simon/.ghci
[1 of 1] Compiling Bug ( Bug.hs, interpreted )
Bug.hs:27:1: warning: [-Wincomplete-patterns]
Pattern match(es) are non-exhaustive
In an equation for ‘bug’: Patterns not matched: _
|
27 | bug (decomposeSrcSpan->L (StringLiteral s)) = s
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Ok, one module loaded.
I've been able to reproduce the issue with all versions of GHC >= 7.8.
Trac metadata
| Trac field | Value |
|---|---|
| Version | 8.6.3 |
| Type | Bug |
| TypeOfFailure | OtherFailure |
| Priority | normal |
| Resolution | Unresolved |
| Component | Compiler |
| Test case | |
| Differential revisions | |
| BlockedBy | |
| Related | |
| Blocking | |
| CC | |
| Operating system | |
| Architecture |
Edited by Ryan Scott