diff options
| author | Reid Barton <rwbarton@gmail.com> | 2017-03-02 16:29:55 -0500 |
|---|---|---|
| committer | Ben Gamari <ben@smart-cactus.org> | 2017-03-02 19:58:01 -0500 |
| commit | fce3d37c367346c67467ce3d56bc015fa9ed6062 (patch) | |
| tree | b387645cf5ee628f67bfede42b6f77e432c667fa /compiler/rename/RnBinds.hs | |
| parent | 0b922909121f6a812d2861a29d0d0d3c7e2fcfce (diff) | |
| download | haskell-fce3d37c367346c67467ce3d56bc015fa9ed6062.tar.gz | |
Don't allow orphan COMPLETE pragmas (#13349)
We might support them properly in the future, but for now it's simpler
to disallow them.
Test Plan: validate
Reviewers: mpickering, austin, bgamari, simonpj
Reviewed By: mpickering, simonpj
Subscribers: simonpj, thomie
Differential Revision: https://phabricator.haskell.org/D3243
Diffstat (limited to 'compiler/rename/RnBinds.hs')
| -rw-r--r-- | compiler/rename/RnBinds.hs | 36 |
1 files changed, 35 insertions, 1 deletions
diff --git a/compiler/rename/RnBinds.hs b/compiler/rename/RnBinds.hs index f8b3347ca5..705befd1bb 100644 --- a/compiler/rename/RnBinds.hs +++ b/compiler/rename/RnBinds.hs @@ -952,10 +952,44 @@ renameSig ctxt sig@(SCCFunSig st v s) -- COMPLETE Sigs can refer to imported IDs which is why we use -- lookupLocatedOccRn rather than lookupSigOccRn -renameSig _ctxt (CompleteMatchSig s (L l bf) mty) +renameSig _ctxt sig@(CompleteMatchSig s (L l bf) mty) = do new_bf <- traverse lookupLocatedOccRn bf new_mty <- traverse lookupLocatedOccRn mty + + this_mod <- fmap tcg_mod getGblEnv + unless (any (nameIsLocalOrFrom this_mod . unLoc) new_bf) $ do + -- Why 'any'? See Note [Orphan COMPLETE pragmas] + addErrCtxt (text "In" <+> ppr sig) $ failWithTc orphanError + return (CompleteMatchSig s (L l new_bf) new_mty, emptyFVs) + where + orphanError :: SDoc + orphanError = + text "Orphan COMPLETE pragmas not supported" $$ + text "A COMPLETE pragma must mention at least one data constructor" $$ + text "or pattern synonym defined in the same module." + +{- +Note [Orphan COMPLETE pragmas] +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +We define a COMPLETE pragma to be a non-orphan if it includes at least +one conlike defined in the current module. Why is this sufficient? +Well if you have a pattern match + + case expr of + P1 -> ... + P2 -> ... + P3 -> ... + +any COMPLETE pragma which mentions a conlike other than P1, P2 or P3 +will not be of any use in verifying that the pattern match is +exhaustive. So as we have certainly read the interface files that +define P1, P2 and P3, we will have loaded all non-orphan COMPLETE +pragmas that could be relevant to this pattern match. + +For now we simply disallow orphan COMPLETE pragmas, as the added +complexity of supporting them properly doesn't seem worthwhile. +-} ppr_sig_bndrs :: [Located RdrName] -> SDoc ppr_sig_bndrs bs = quotes (pprWithCommas ppr bs) |
