summaryrefslogtreecommitdiff
path: root/compiler/GHC/Rename/Names.hs
diff options
context:
space:
mode:
authorAdam Gundry <adam@well-typed.com>2020-04-27 23:22:59 +0100
committerMarge Bot <ben+marge-bot@smart-cactus.org>2020-05-08 15:29:41 -0400
commit7a763cff78d2d4b23d05554e68138678cb4ba627 (patch)
tree16f7aabfff8879bc7cb027971f5d15fefddb1fce /compiler/GHC/Rename/Names.hs
parent926d2aab83dc6068cba76f71a19b040eddc6dee9 (diff)
downloadhaskell-7a763cff78d2d4b23d05554e68138678cb4ba627.tar.gz
Reject all duplicate declarations involving DuplicateRecordFields (fixes #17965)
This fixes a bug that resulted in some programs being accepted that used the same identifier as a field label and another declaration, depending on the order they appeared in the source code.
Diffstat (limited to 'compiler/GHC/Rename/Names.hs')
-rw-r--r--compiler/GHC/Rename/Names.hs12
1 files changed, 7 insertions, 5 deletions
diff --git a/compiler/GHC/Rename/Names.hs b/compiler/GHC/Rename/Names.hs
index df39d01adb..cd39ed701d 100644
--- a/compiler/GHC/Rename/Names.hs
+++ b/compiler/GHC/Rename/Names.hs
@@ -638,9 +638,12 @@ extendGlobalRdrEnvRn avails new_fixities
| otherwise
= return (extendGlobalRdrEnv env gre)
where
- name = gre_name gre
- occ = nameOccName name
- dups = filter isLocalGRE (lookupGlobalRdrEnv env occ)
+ occ = greOccName gre
+ dups = filter isDupGRE (lookupGlobalRdrEnv env occ)
+ -- Duplicate GREs are those defined locally with the same OccName,
+ -- except cases where *both* GREs are DuplicateRecordFields (#17965).
+ isDupGRE gre' = isLocalGRE gre'
+ && not (isOverloadedRecFldGRE gre && isOverloadedRecFldGRE gre')
{- *********************************************************************
@@ -1767,14 +1770,13 @@ addDupDeclErr gres@(gre : _)
= addErrAt (getSrcSpan (last sorted_names)) $
-- Report the error at the later location
vcat [text "Multiple declarations of" <+>
- quotes (ppr (nameOccName name)),
+ quotes (ppr (greOccName gre)),
-- NB. print the OccName, not the Name, because the
-- latter might not be in scope in the RdrEnv and so will
-- be printed qualified.
text "Declared at:" <+>
vcat (map (ppr . nameSrcLoc) sorted_names)]
where
- name = gre_name gre
sorted_names =
sortBy (SrcLoc.leftmost_smallest `on` nameSrcSpan)
(map gre_name gres)