summaryrefslogtreecommitdiff
path: root/compiler
diff options
context:
space:
mode:
authorAdam Gundry <adam@well-typed.com>2021-01-26 22:02:08 +0000
committerMarge Bot <ben+marge-bot@smart-cactus.org>2021-02-16 16:39:14 -0500
commit7686f9f80d31d724b2e84b229de5efffbe6e45b4 (patch)
treebe32d6fb87cf5984fcf7b7de76121b6ac6c93cc0 /compiler
parentc2029001d0f717dad68770a652262445bbec1c91 (diff)
downloadhaskell-7686f9f80d31d724b2e84b229de5efffbe6e45b4.tar.gz
Avoid false redundant import warning with DisambiguateRecordFields
Fixes #17853. We mustn't discard the result of pickGREs, because doing so might lead to incorrect redundant import warnings.
Diffstat (limited to 'compiler')
-rw-r--r--compiler/GHC/Rename/Env.hs14
1 files changed, 8 insertions, 6 deletions
diff --git a/compiler/GHC/Rename/Env.hs b/compiler/GHC/Rename/Env.hs
index 48ec8db86c..4b5d5d7af3 100644
--- a/compiler/GHC/Rename/Env.hs
+++ b/compiler/GHC/Rename/Env.hs
@@ -502,13 +502,15 @@ lookupRecFieldOcc mb_con rdr_name
; env <- getGlobalRdrEnv
; let lbl = occNameFS (rdrNameOcc rdr_name)
mb_field = do fl <- find ((== lbl) . flLabel) flds
- -- We have the label, now check it is in
- -- scope (with the correct qualifier if
- -- there is one, hence calling pickGREs).
+ -- We have the label, now check it is in scope. If
+ -- there is a qualifier, use pickGREs to check that
+ -- the qualifier is correct, and return the filtered
+ -- GRE so we get import usage right (see #17853).
gre <- lookupGRE_FieldLabel env fl
- guard (not (isQual rdr_name
- && null (pickGREs rdr_name [gre])))
- return (fl, gre)
+ if isQual rdr_name
+ then do gre' <- listToMaybe (pickGREs rdr_name [gre])
+ return (fl, gre')
+ else return (fl, gre)
; case mb_field of
Just (fl, gre) -> do { addUsedGRE True gre
; return (flSelector fl) }