Fix collect_lpat's treatment of HsSplicedPats
authorRyan Scott <ryan.gl.scott@gmail.com>
Thu, 11 May 2017 19:46:02 +0000 (15:46 -0400)
committerBen Gamari <ben@smart-cactus.org>
Thu, 11 May 2017 21:33:12 +0000 (17:33 -0400)
`collect_lpat` was missing a case for `HsSplicedPat`, which caused
incorrect renaming of TH-spliced pattern variables.

Fixes #13473.

Test Plan: make test TEST=T13473

Reviewers: facundominguez, austin, bgamari

Reviewed By: bgamari

Subscribers: rwbarton, thomie

GHC Trac Issues: #13473

Differential Revision: https://phabricator.haskell.org/D3572

compiler/hsSyn/HsUtils.hs
testsuite/tests/th/T13473.hs [new file with mode: 0644]
testsuite/tests/th/T13473.stdout [new file with mode: 0644]
testsuite/tests/th/T13473a.hs [new file with mode: 0644]
testsuite/tests/th/all.T

index 2b3a5c6..a15aa15 100644 (file)
@@ -965,6 +965,9 @@ collect_lpat (L _ pat) bndrs
 
     go (SigPatIn pat _)           = collect_lpat pat bndrs
     go (SigPatOut pat _)          = collect_lpat pat bndrs
+
+    go (SplicePat (HsSpliced _ (HsSplicedPat pat)))
+                                  = go pat
     go (SplicePat _)              = bndrs
     go (CoPat _ pat _)            = go pat
 
diff --git a/testsuite/tests/th/T13473.hs b/testsuite/tests/th/T13473.hs
new file mode 100644 (file)
index 0000000..d977626
--- /dev/null
@@ -0,0 +1,13 @@
+{-# LANGUAGE QuasiQuotes #-}
+{-# LANGUAGE TemplateHaskell #-}
+module Main where
+
+import Language.Haskell.TH
+import T13473a
+
+[quoter|y|] = 1
+
+main :: IO ()
+main = do
+  let $(varP $ mkName "x") = 1 in print x
+  print y
diff --git a/testsuite/tests/th/T13473.stdout b/testsuite/tests/th/T13473.stdout
new file mode 100644 (file)
index 0000000..6ed281c
--- /dev/null
@@ -0,0 +1,2 @@
+1
+1
diff --git a/testsuite/tests/th/T13473a.hs b/testsuite/tests/th/T13473a.hs
new file mode 100644 (file)
index 0000000..fcd6ebb
--- /dev/null
@@ -0,0 +1,10 @@
+module T13473a where
+
+import Language.Haskell.TH
+import Language.Haskell.TH.Quote
+
+quoter :: QuasiQuoter
+quoter = QuasiQuoter { quotePat  = varP . mkName
+                     , quoteExp  = undefined
+                     , quoteDec  = undefined
+                     , quoteType = undefined }
index fd4530a..40e3b17 100644 (file)
@@ -381,6 +381,8 @@ test('T13123', normal, compile, ['-v0'])
 test('T13098', normal, compile, ['-v0'])
 test('T11046', normal, multimod_compile, ['T11046','-v0'])
 test('T13366', normal, compile_and_run, ['-lstdc++ -v0'])
+test('T13473', normal, multimod_compile_and_run,
+     ['T13473.hs', '-v0 ' + config.ghc_th_way_flags])
 test('T13587', expect_broken(13587), compile_and_run, ['-v0'])
 test('T13618', normal, compile_and_run, ['-v0'])
 test('T13642', normal, compile_fail, ['-v0'])