diff options
| author | Matthew Pickering <matthewtpickering@gmail.com> | 2016-10-01 17:55:26 -0400 |
|---|---|---|
| committer | Ben Gamari <ben@smart-cactus.org> | 2016-10-01 20:01:29 -0400 |
| commit | 1851349acd9e73f1c18d68f70d5cf7b46a843cb5 (patch) | |
| tree | b61033677bd91a7dbcc8d55326f9a25c297cf79c /compiler/rename/RnPat.hs | |
| parent | 2d6642bd1956edf8b842c07d78e83c500246998a (diff) | |
| download | haskell-1851349acd9e73f1c18d68f70d5cf7b46a843cb5.tar.gz | |
Don't warn about name shadowing when renaming the patten in a PatSyn decl
Previously the renamer assumed that *any* time we renamed a pattern, the
pattern was introducing new binders. This isn't true in pattern synonym
declarations where the pattern is used as part of a definition.
We add a special case to not warn in this situation.
Reviewers: simonpj, austin, bgamari
Reviewed By: simonpj
Subscribers: simonpj, thomie
Differential Revision: https://phabricator.haskell.org/D2545
GHC Trac Issues: #12615
Diffstat (limited to 'compiler/rename/RnPat.hs')
| -rw-r--r-- | compiler/rename/RnPat.hs | 30 |
1 files changed, 26 insertions, 4 deletions
diff --git a/compiler/rename/RnPat.hs b/compiler/rename/RnPat.hs index 7e41bec9d2..e67be63fa4 100644 --- a/compiler/rename/RnPat.hs +++ b/compiler/rename/RnPat.hs @@ -62,7 +62,7 @@ import TysWiredIn ( nilDataCon ) import DataCon import qualified GHC.LanguageExtensions as LangExt -import Control.Monad ( when, liftM, ap ) +import Control.Monad ( when, liftM, ap, unless ) import Data.Ratio {- @@ -248,6 +248,25 @@ We want to "see" this use, and in let-bindings we collect all uses and report unused variables at the binding level. So we must use bindLocalNames here, *not* bindLocalNameFV. Trac #3943. + +Note: [Don't report shadowing for pattern synonyms] +There is one special context where a pattern doesn't introduce any new binders - +pattern synonym declarations. Therefore we don't check to see if pattern +variables shadow existing identifiers as they are never bound to anything +and have no scope. + +Without this check, there would be quite a cryptic warning that the `x` +in the RHS of the pattern synonym declaration shadowed the top level `x`. + +``` +x :: () +x = () + +pattern P x = Just x +``` + +See #12615 for some more examples. + ********************************************************* * * External entry points @@ -293,9 +312,12 @@ rnPats ctxt pats thing_inside -- check incrementally for duplicates; -- Nor can we check incrementally for shadowing, else we'll -- complain *twice* about duplicates e.g. f (x,x) = ... - ; addErrCtxt doc_pat $ - checkDupAndShadowedNames envs_before $ - collectPatsBinders pats' + -- + -- See note [Don't report shadowing for pattern synonyms] + ; unless (isPatSynCtxt ctxt) + (addErrCtxt doc_pat $ + checkDupAndShadowedNames envs_before $ + collectPatsBinders pats') ; thing_inside pats' } } where doc_pat = text "In" <+> pprMatchContext ctxt |
