Commit a89bb806 authored by Ryan Scott's avatar Ryan Scott

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
parent 6982ee99
......@@ -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
......
{-# LANGUAGE PatternSynonyms #-}
module T14114 where
pattern Foo1 a <- (a,a)
pattern Foo2 a = (a,a)
pattern Foo3 a <- (a,a) where
Foo3 a = (a,a)
T14114.hs:4:20: error:
• Conflicting definitions for ‘a’
Bound at: T14114.hs:4:20
T14114.hs:4:22
• In a pattern synonym declaration
T14114.hs:5:20: error:
• Conflicting definitions for ‘a’
Bound at: T14114.hs:5:20
T14114.hs:5:22
• In a pattern synonym declaration
T14114.hs:6:20: error:
• Conflicting definitions for ‘a’
Bound at: T14114.hs:6:20
T14114.hs:6:22
• In a pattern synonym declaration
......@@ -36,3 +36,4 @@ test('T12819', normal, compile_fail, [''])
test('UnliftedPSBind', normal, compile_fail, [''])
test('T13349', normal, compile_fail, [''])
test('T13470', normal, compile_fail, [''])
test('T14114', normal, compile_fail, [''])
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment