Commit 7686f9f8 authored by Adam Gundry's avatar Adam Gundry Committed by Marge Bot

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.
parent c2029001
......@@ -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) }
{-# LANGUAGE DisambiguateRecordFields #-}
{-# OPTIONS_GHC -Werror=unused-imports #-}
module T17853 where
-- All the imports of T17853A are necessary, so they should not be reported as
-- redundant. DisambiguateRecordFields has special logic for looking up field
-- labels in record field construction because the module qualifier is optional.
-- Previously this incorrectly reported imports as redundant if they were used
-- only for fields that were in scope under a different prefix (see #17853).
import qualified T17853A
import qualified T17853A as X (X(..))
import qualified T17853A as Y (Y(..))
main :: IO ()
main = do
print T17853A.X { = "hello" }
print T17853A.Y { Y.age = 3 }
module T17853A where
data X = X { name :: String } deriving Show
data Y = Y { age :: Int } deriving Show
......@@ -177,3 +177,4 @@ test('T17837', normal, compile, [''])
test('T18497', [], makefile_test, ['T18497'])
test('T18264', [], makefile_test, ['T18264'])
test('T18302', expect_broken(18302), compile, [''])
test('T17853', [], multimod_compile, ['T17853', '-v0'])
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