diff options
author | Matthew Pickering <matthewtpickering@gmail.com> | 2017-01-18 13:25:30 +0000 |
---|---|---|
committer | Matthew Pickering <matthewtpickering@gmail.com> | 2017-01-26 00:22:46 +0000 |
commit | 1a3f1eebf81952accb6340252816211c7d391300 (patch) | |
tree | 03fbe6fac6518c3da73282266833941d76b34736 /compiler/rename/RnBinds.hs | |
parent | 078c21140d4f27e586c9fa893d4ac94d28d6013c (diff) | |
download | haskell-1a3f1eebf81952accb6340252816211c7d391300.tar.gz |
COMPLETE pragmas for enhanced pattern exhaustiveness checking
This patch adds a new pragma so that users can specify `COMPLETE` sets of
`ConLike`s in order to sate the pattern match checker.
A function which matches on all the patterns in a complete grouping
will not cause the exhaustiveness checker to emit warnings.
```
pattern P :: ()
pattern P = ()
{-# COMPLETE P #-}
foo P = ()
```
This example would previously have caused the checker to warn that
all cases were not matched even though matching on `P` is sufficient to
make `foo` covering. With the addition of the pragma, the compiler
will recognise that matching on `P` alone is enough and not emit
any warnings.
Reviewers: goldfire, gkaracha, alanz, austin, bgamari
Reviewed By: alanz
Subscribers: lelf, nomeata, gkaracha, thomie
Differential Revision: https://phabricator.haskell.org/D2669
GHC Trac Issues: #8779
Diffstat (limited to 'compiler/rename/RnBinds.hs')
-rw-r--r-- | compiler/rename/RnBinds.hs | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/compiler/rename/RnBinds.hs b/compiler/rename/RnBinds.hs index c232e76ea0..f6a22f5df2 100644 --- a/compiler/rename/RnBinds.hs +++ b/compiler/rename/RnBinds.hs @@ -950,6 +950,13 @@ renameSig ctxt sig@(SCCFunSig st v s) = do { new_v <- lookupSigOccRn ctxt sig v ; return (SCCFunSig st new_v s, emptyFVs) } +-- COMPLETE Sigs can refer to imported IDs which is why we use +-- lookupLocatedOccRn rather than lookupSigOccRn +renameSig _ctxt (CompleteMatchSig s (L l bf) mty) + = do new_bf <- traverse lookupLocatedOccRn bf + new_mty <- traverse lookupLocatedOccRn mty + return (CompleteMatchSig s (L l new_bf) new_mty, emptyFVs) + ppr_sig_bndrs :: [Located RdrName] -> SDoc ppr_sig_bndrs bs = quotes (pprWithCommas ppr bs) @@ -991,6 +998,9 @@ okHsSig ctxt (L _ sig) (SCCFunSig {}, HsBootCtxt {}) -> False (SCCFunSig {}, _) -> True + (CompleteMatchSig {}, TopSigCtxt {} ) -> True + (CompleteMatchSig {}, _) -> False + ------------------- findDupSigs :: [LSig RdrName] -> [[(Located RdrName, Sig RdrName)]] -- Check for duplicates on RdrName version, |