[commit: ghc] master: Drop module qualifier from punned record fields (#11662) (bd681bc)
git at git.haskell.org
git at git.haskell.org
Sat Mar 5 20:15:36 UTC 2016
Repository : ssh://git@git.haskell.org/ghc
On branch : master
Link : http://ghc.haskell.org/trac/ghc/changeset/bd681bceba535d0e67e8182964dc167877e4756d/ghc
>---------------------------------------------------------------
commit bd681bceba535d0e67e8182964dc167877e4756d
Author: Adam Gundry <adam at well-typed.com>
Date: Sat Mar 5 20:02:32 2016 +0100
Drop module qualifier from punned record fields (#11662)
A record pattern match, construction or update like
`Rec { Mod.f }` should expand to `Rec { Mod.f = f }` rather
than `Rec { Mod.f = Mod.f }`.
Test Plan: New test rename/should_compile/T11662
Reviewers: austin, bgamari
Reviewed By: bgamari
Subscribers: hesselink, thomie
Differential Revision: https://phabricator.haskell.org/D1965
GHC Trac Issues: #11662
>---------------------------------------------------------------
bd681bceba535d0e67e8182964dc167877e4756d
compiler/rename/RnPat.hs | 8 ++++++--
testsuite/tests/rename/should_compile/T11662.hs | 14 ++++++++++++++
testsuite/tests/rename/should_compile/T11662_A.hs | 3 +++
testsuite/tests/rename/should_compile/all.T | 4 ++++
4 files changed, 27 insertions(+), 2 deletions(-)
diff --git a/compiler/rename/RnPat.hs b/compiler/rename/RnPat.hs
index eab3090..98ca38b 100644
--- a/compiler/rename/RnPat.hs
+++ b/compiler/rename/RnPat.hs
@@ -561,7 +561,9 @@ rnHsRecFields ctxt mk_arg (HsRecFields { rec_flds = flds, rec_dotdot = dotdot })
= do { sel <- setSrcSpan loc $ lookupRecFieldOcc parent doc lbl
; arg' <- if pun
then do { checkErr pun_ok (badPun (L loc lbl))
- ; return (L loc (mk_arg loc lbl)) }
+ -- Discard any module qualifier (#11662)
+ ; let arg_rdr = mkRdrUnqual (rdrNameOcc lbl)
+ ; return (L loc (mk_arg loc arg_rdr)) }
else return arg
; return (L l (HsRecField { hsRecFieldLbl
= L loc (FieldOcc (L ll lbl) sel)
@@ -689,7 +691,9 @@ rnHsRecUpdFields flds
else fmap Left $ lookupGlobalOccRn lbl
; arg' <- if pun
then do { checkErr pun_ok (badPun (L loc lbl))
- ; return (L loc (HsVar (L loc lbl))) }
+ -- Discard any module qualifier (#11662)
+ ; let arg_rdr = mkRdrUnqual (rdrNameOcc lbl)
+ ; return (L loc (HsVar (L loc arg_rdr))) }
else return arg
; (arg'', fvs) <- rnLExpr arg'
diff --git a/testsuite/tests/rename/should_compile/T11662.hs b/testsuite/tests/rename/should_compile/T11662.hs
new file mode 100644
index 0000000..e9afda0
--- /dev/null
+++ b/testsuite/tests/rename/should_compile/T11662.hs
@@ -0,0 +1,14 @@
+{-# LANGUAGE NamedFieldPuns #-}
+module T11662 where
+
+import T11662_A (Rec (Rec))
+import qualified T11662_A
+
+g :: Rec -> Integer
+g (Rec { T11662_A.f }) = f
+
+h :: Integer -> Rec -> Rec
+h f r = r { T11662_A.f }
+
+k :: Integer -> Rec
+k f = Rec { T11662_A.f }
diff --git a/testsuite/tests/rename/should_compile/T11662_A.hs b/testsuite/tests/rename/should_compile/T11662_A.hs
new file mode 100644
index 0000000..1d4f625
--- /dev/null
+++ b/testsuite/tests/rename/should_compile/T11662_A.hs
@@ -0,0 +1,3 @@
+module T11662_A where
+
+data Rec = Rec { f :: Integer }
diff --git a/testsuite/tests/rename/should_compile/all.T b/testsuite/tests/rename/should_compile/all.T
index 65f92e2..ede9f19 100644
--- a/testsuite/tests/rename/should_compile/all.T
+++ b/testsuite/tests/rename/should_compile/all.T
@@ -233,3 +233,7 @@ test('T11164',
test('T11167', normal, compile, [''])
test('T11167_ambig', normal, compile, [''])
test('T10625', normal, compile, [''])
+test('T11662',
+ [extra_clean(['T11662_A.hi', 'T11662_A.o'])],
+ multimod_compile,
+ ['T11662', '-v0'])
More information about the ghc-commits
mailing list