summaryrefslogtreecommitdiff
path: root/compiler/rename
diff options
context:
space:
mode:
authorRyan Scott <ryan.gl.scott@gmail.com>2017-08-22 09:28:49 -0400
committerRyan Scott <ryan.gl.scott@gmail.com>2017-08-22 09:28:49 -0400
commita89bb806c58d3e601b37d6f2c4ebec6514fd2776 (patch)
treeb2bef8ba5b726ac2ef726ec29eee5d6b592a93b8 /compiler/rename
parent6982ee99fb97c252c3faf37faae34131fb66f67c (diff)
downloadhaskell-a89bb806c58d3e601b37d6f2c4ebec6514fd2776.tar.gz
Fix #14114 by checking for duplicate vars on pattern synonym RHSes
Summary: Because we weren't checking for duplicate variables on the right-hand sides of pattern synonyms, bogus definitions like this one passed the renamer: ```lang=haskell pattern Foo a <- (a,a) ``` Luckily, the fix is simple. Test Plan: make test TEST=T14114 Reviewers: mpickering, austin, bgamari, simonpj Reviewed By: simonpj Subscribers: simonpj, rwbarton, thomie GHC Trac Issues: #14114 Differential Revision: https://phabricator.haskell.org/D3866
Diffstat (limited to 'compiler/rename')
-rw-r--r--compiler/rename/RnPat.hs15
1 files changed, 8 insertions, 7 deletions
diff --git a/compiler/rename/RnPat.hs b/compiler/rename/RnPat.hs
index 320e4f3d12..9b439a7b19 100644
--- a/compiler/rename/RnPat.hs
+++ b/compiler/rename/RnPat.hs
@@ -47,8 +47,8 @@ import RnEnv
import RnFixity
import RnUtils ( HsDocContext(..), newLocalBndrRn, bindLocalNames
, warnUnusedMatches, newLocalBndrRn
- , checkDupAndShadowedNames, checkTupSize
- , unknownSubordinateErr )
+ , checkDupNames, checkDupAndShadowedNames
+ , checkTupSize , unknownSubordinateErr )
import RnTypes
import PrelNames
import TyCon ( tyConName )
@@ -67,7 +67,7 @@ import TysWiredIn ( nilDataCon )
import DataCon
import qualified GHC.LanguageExtensions as LangExt
-import Control.Monad ( when, liftM, ap, unless )
+import Control.Monad ( when, liftM, ap )
import qualified Data.List.NonEmpty as NE
import Data.Ratio
@@ -321,10 +321,11 @@ rnPats ctxt pats thing_inside
-- complain *twice* about duplicates e.g. f (x,x) = ...
--
-- See note [Don't report shadowing for pattern synonyms]
- ; unless (isPatSynCtxt ctxt)
- (addErrCtxt doc_pat $
- checkDupAndShadowedNames envs_before $
- collectPatsBinders pats')
+ ; let bndrs = collectPatsBinders pats'
+ ; addErrCtxt doc_pat $
+ if isPatSynCtxt ctxt
+ then checkDupNames bndrs
+ else checkDupAndShadowedNames envs_before bndrs
; thing_inside pats' } }
where
doc_pat = text "In" <+> pprMatchContext ctxt