Skip to content

Pattern to type transformation doesn't work with TH splices.

Summary

pat_to_type_pat doesn't perform transformation for SplicePat, so it is not possible to use TH splices to create a pattern for forall->

Steps to reproduce

{-# LANGUAGE TemplateHaskell, RequiredTypeArguments #-}
module T where

g :: forall a -> ()
g $([p| a |]) = () -- Ill-formed type pattern: a_a285

Expected behavior

That should compile.

The fix is straightforward, just a couple lines of code with a new equation in pat_to_type_pat function.

diff --git a/compiler/GHC/Tc/Gen/Pat.hs b/compiler/GHC/Tc/Gen/Pat.hs
index 99ffe6561b..eaf263907d 100644
--- a/compiler/GHC/Tc/Gen/Pat.hs
+++ b/compiler/GHC/Tc/Gen/Pat.hs
@@ -534,6 +534,9 @@ pat_to_type_pat (SigPat _ pat sig_ty)
 pat_to_type_pat (ParPat _ pat)
   = do { HsTP x t <- pat_to_type_pat (unLoc pat)
        ; return (HsTP x (noLocA (HsParTy noAnn t))) }
+pat_to_type_pat (SplicePat (HsUntypedSpliceTop mod_finalizers pat) splice) = do
+      { HsTP x t <- pat_to_type_pat pat
+      ; return (HsTP x (noLocA (HsSpliceTy (HsUntypedSpliceTop mod_finalizers t) splice))) }
 pat_to_type_pat pat =
   -- There are other cases to handle (ConPat, ListPat, TuplePat, etc), but these
   -- would always be rejected by the unification in `tcHsTyPat`, so it's fine to
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information