Skip to content

Template Haskell + hs-boot = Not in scope during type checking, but it passed the renamer

I don't think this is a very harmful bug but it definitely is a bug. Consider:

-- A.hs-boot
module A where
data T

-- B.hs
module B (module A) where
import {-# SOURCE #-} A

-- A.hs
{-# LANGUAGE TemplateHaskell #-}
module A where
import qualified B
import Language.Haskell.TH
f :: B.T -> B.T
f x = x
$( return [] )
data T = T B.T

The point of the splice is to convince GHC to typecheck f :: B.T -> B.T before it typechecks the type declaration. But this is not going to work, because tcLookupGlobal is going to bail if (1) T is not in the tcg_type_env and (2) T comes from this module.

It would be a simple matter to improve the error message but from a user's perspective, there is no good reason for this to not typecheck. On the implementation side, I am sympathetic to not letting this typecheck: if it does typecheck, then some TyCons will incorrectly refer to the definition from the hs-boot file, rather than our local definition.

Trac metadata
Trac field Value
Version 8.0.1-rc2
Type Bug
TypeOfFailure OtherFailure
Priority low
Resolution Unresolved
Component Compiler (Type checker)
Test case
Differential revisions
BlockedBy
Related
Blocking
CC
Operating system
Architecture
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information