Fix #15550 by quoting RULE names during TH conversion
authorRyan Scott <ryan.gl.scott@gmail.com>
Mon, 27 Aug 2018 12:02:42 +0000 (14:02 +0200)
committerBen Gamari <ben@smart-cactus.org>
Sun, 16 Sep 2018 16:31:17 +0000 (12:31 -0400)
Summary:
When converting a `RuleP` to a GHC source `RuleD` during TH
conversion, we were stupidly not double-quoting the name of the rule.
Easily fixed.

Test Plan: make test TEST=T15550

Reviewers: goldfire, bgamari, simonpj

Reviewed By: simonpj

Subscribers: simonpj, rwbarton, carter

GHC Trac Issues: #15550

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

(cherry picked from commit 5e6cf2a9301a5473ff9c5319b96de941b1ad72dd)

compiler/hsSyn/Convert.hs
testsuite/tests/th/T15550.hs [new file with mode: 0644]
testsuite/tests/th/T15550.stderr [new file with mode: 0644]
testsuite/tests/th/all.T

index b637a3c..1e6611c 100644 (file)
@@ -706,8 +706,8 @@ cvtPragmaD (RuleP nm bndrs lhs rhs phases)
        ; rhs'   <- cvtl rhs
        ; returnJustL $ Hs.RuleD noExt
             $ HsRules noExt (SourceText "{-# RULES")
-                      [noLoc $ HsRule noExt (noLoc (SourceText nm,nm')) act
-                                                  bndrs' lhs' rhs']
+                      [noLoc $ HsRule noExt (noLoc (quotedSourceText nm,nm'))
+                                                  act bndrs' lhs' rhs']
        }
 
 cvtPragmaD (AnnP target exp)
diff --git a/testsuite/tests/th/T15550.hs b/testsuite/tests/th/T15550.hs
new file mode 100644 (file)
index 0000000..538064c
--- /dev/null
@@ -0,0 +1,8 @@
+{-# LANGUAGE TemplateHaskell #-}
+module T15550 where
+
+$([d| myId :: a -> a
+      myId x = x
+      {-# NOINLINE [1] myId #-}
+      {-# RULES "myId" forall x. myId x = x #-}
+    |])
diff --git a/testsuite/tests/th/T15550.stderr b/testsuite/tests/th/T15550.stderr
new file mode 100644 (file)
index 0000000..8169d75
--- /dev/null
@@ -0,0 +1,11 @@
+T15550.hs:(4,3)-(8,6): Splicing declarations
+    [d| {-# RULES "myId" forall x. myId x = x #-}
+        
+        myId :: a -> a
+        myId x = x
+        {-# NOINLINE [1] myId #-} |]
+  ======>
+    myId :: a -> a
+    myId x = x
+    {-# NOINLINE [1] myId #-}
+    {-# RULES "myId" forall x. myId x = x #-}
index fb62bd2..280200e 100644 (file)
@@ -421,3 +421,4 @@ test('T15321', normal, compile_fail, [''])
 test('T15365', normal, compile, ['-v0 -ddump-splices -dsuppress-uniques'])
 test('T15518', normal, compile, ['-v0 -ddump-splices -dsuppress-uniques'])
 test('T15502', normal, compile, ['-v0 -ddump-splices -dsuppress-uniques'])
+test('T15550', normal, compile, ['-v0 -ddump-splices -dsuppress-uniques'])