Skip to content

TemplateHaskell typechecking regression in HEAD

(Originally observed in a head.hackage CI job here.)

The what4-1.4 Hackage library currently fails to build with GHC HEAD + head.hackage. Here is a minimized example of the issue:

{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE TemplateHaskell #-}
module Bug where

good :: (forall a. a -> a) -> b -> b
good = \g x -> g x

bad :: (forall a. a -> a) -> b -> b
bad = $([| \g x -> g x |])

This compiles with GHC 9.8 and earlier, but fails to typecheck with GHC HEAD at commit b938950d:

$ ghc-head Bug.hs
[1 of 1] Compiling Bug              ( Bug.hs, Bug.o )

Bug.hs:9:8: error: [GHC-83865]
    • Couldn't match type: b -> b
                     with: forall a. a -> a
      Expected: (forall a. a -> a) -> b -> b
        Actual: (b -> b) -> b -> b
    • In the expression: \ g_a24j x_a24k -> g_a24j x_a24k
      In an equation for ‘bad’: bad = (\ g_a24j x_a24k -> g_a24j x_a24k)
    • Relevant bindings include
        bad :: (forall a. a -> a) -> b -> b (bound at Bug.hs:9:1)
  |
9 | bad = $([| \g x -> g x |])
  |        ^^^^^^^^^^^^^^^^^^^

I think both of these should be accepted, as the only difference between good and bad is the presence of a Template Haskell splice.

While I haven't had time to bisect the issue just yet, my first hunch is to suspect commit !10911 (closed) (Look through TH splices in splitHsApps).

Edited by Ryan Scott
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information