[commit: ghc] ghc-8.0: Drop module qualifier from punned record fields (#11662) (40d08b6)
git at git.haskell.org
git at git.haskell.org
Mon Mar 7 22:46:12 UTC 2016
Repository : ssh://git@git.haskell.org/ghc
On branch : ghc-8.0
Link : http://ghc.haskell.org/trac/ghc/changeset/40d08b6286468ba1418cd19ed8d37c1650711049/ghc
>---------------------------------------------------------------
commit 40d08b6286468ba1418cd19ed8d37c1650711049
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
(cherry picked from commit bd681bceba535d0e67e8182964dc167877e4756d)
>---------------------------------------------------------------
40d08b6286468ba1418cd19ed8d37c1650711049
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 460954d..51ddea9 100644
--- a/compiler/rename/RnPat.hs
+++ b/compiler/rename/RnPat.hs
@@ -562,7 +562,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)
@@ -690,7 +692,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 8c120cd..31495af 100644
--- a/testsuite/tests/rename/should_compile/all.T
+++ b/testsuite/tests/rename/should_compile/all.T
@@ -232,3 +232,7 @@ test('T11164',
multimod_compile, ['T11164', '-v0'])
test('T11167', normal, compile, [''])
test('T11167_ambig', normal, compile, [''])
+test('T11662',
+ [extra_clean(['T11662_A.hi', 'T11662_A.o'])],
+ multimod_compile,
+ ['T11662', '-v0'])
More information about the ghc-commits
mailing list