summaryrefslogtreecommitdiff
path: root/testsuite
diff options
context:
space:
mode:
authorsheaf <sam.derbyshire@gmail.com>2023-04-07 18:36:56 +0200
committerMarge Bot <ben+marge-bot@smart-cactus.org>2023-04-07 22:30:07 -0400
commit3ba77b369a170ba68f4eb5c8f3ae13e03dcbb28d (patch)
treec1296a7fc789c66bc79ee1b345f67d2a0841ae48 /testsuite
parent6a788f0ad465cf49673b187c5feeae80b738ce54 (diff)
downloadhaskell-3ba77b369a170ba68f4eb5c8f3ae13e03dcbb28d.tar.gz
Renamer: don't call addUsedGRE on an exact Name
When looking up a record field in GHC.Rename.Env.lookupRecFieldOcc, we could end up calling addUsedGRE on an exact Name, which would then lead to a panic in the bestImport function: it would be incapable of processing a GRE which is not local but also not brought into scope by any imports (as it is referred to by its unique instead). Fixes #23240
Diffstat (limited to 'testsuite')
-rw-r--r--testsuite/tests/rename/should_compile/T23240.hs14
-rw-r--r--testsuite/tests/rename/should_compile/T23240_aux.hs10
-rw-r--r--testsuite/tests/rename/should_compile/all.T1
3 files changed, 25 insertions, 0 deletions
diff --git a/testsuite/tests/rename/should_compile/T23240.hs b/testsuite/tests/rename/should_compile/T23240.hs
new file mode 100644
index 0000000000..f498e9ba50
--- /dev/null
+++ b/testsuite/tests/rename/should_compile/T23240.hs
@@ -0,0 +1,14 @@
+{-# LANGUAGE Haskell2010 #-}
+{-# LANGUAGE TemplateHaskell #-}
+
+-- Crucial to triggering the bug.
+{-# LANGUAGE DisambiguateRecordFields #-}
+
+-- Need to enable the unused imports warning to trigger the bug.
+{-# OPTIONS_GHC -Wunused-imports #-}
+
+module T23240 ( test ) where
+import T23240_aux ( D, mkD )
+
+test :: D
+test = $$mkD
diff --git a/testsuite/tests/rename/should_compile/T23240_aux.hs b/testsuite/tests/rename/should_compile/T23240_aux.hs
new file mode 100644
index 0000000000..2ba6404efe
--- /dev/null
+++ b/testsuite/tests/rename/should_compile/T23240_aux.hs
@@ -0,0 +1,10 @@
+{-# LANGUAGE Haskell2010 #-}
+{-# LANGUAGE TemplateHaskell #-}
+
+module T23240_aux where
+
+import Language.Haskell.TH ( CodeQ )
+
+data D = MkD { myFld :: () }
+mkD :: CodeQ D
+mkD = [|| MkD { myFld = () } ||]
diff --git a/testsuite/tests/rename/should_compile/all.T b/testsuite/tests/rename/should_compile/all.T
index 55f58fcebc..7885713c04 100644
--- a/testsuite/tests/rename/should_compile/all.T
+++ b/testsuite/tests/rename/should_compile/all.T
@@ -209,3 +209,4 @@ test('ImportNullaryRecordWildcard', [extra_files(['NullaryRecordWildcard.hs', 'N
test('GHCINullaryRecordWildcard', combined_output, ghci_script, ['GHCINullaryRecordWildcard.script'])
test('GHCIImplicitImportNullaryRecordWildcard', combined_output, ghci_script, ['GHCIImplicitImportNullaryRecordWildcard.script'])
test('T22122', [expect_broken(22122), extra_files(['T22122_aux.hs'])], multimod_compile, ['T22122', '-v0'])
+test('T23240', [req_th, extra_files(['T23240_aux.hs'])], multimod_compile, ['T23240', '-v0'])