Opened 7 years ago

Closed 7 years ago

Last modified 7 years ago

#5795 closed bug (fixed)

Breaking the staging restriction in type splices causes GHC panic

Reported by: reinerp Owned by:
Priority: normal Milestone: 7.4.2
Component: Template Haskell Version: 7.4.1-rc1
Keywords: Cc:
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: None/Unknown Test Case: th/T5795
Blocked By: Blocking:
Related Tickets: Differential Rev(s):
Wiki Page:


Test case:

{-# LANGUAGE TemplateHaskell #-}
module B where

import Language.Haskell.TH

ty :: Q Type
ty = [t| Int |]

f :: $ty
f = undefined

The error message is:

    GHC internal error: `ty' is not in scope during type checking, but it passed the renamer
    tcl_env of environment: []
    In the expression: ty
    In the type signature for `f': f :: $ty

This is the same error as in #5792.

Change History (3)

comment:1 Changed 7 years ago by igloo

difficulty: Unknown
Milestone: 7.4.2

Thanks for the report.

comment:2 Changed 7 years ago by simonpj@…

commit 6d46439c1c0e3765827dde26077ff45f85e210bd

Author: Simon Peyton Jones <>
Date:   Thu Apr 5 11:37:02 2012 +0100

    Improve error reporting for out-of-scope variables
    Sometimes when a variable is out of scope in the type-checker,
    it's not a GHC bug, but rather a TH staging error.  See
    Note [Out of scope might be a staging error] in TcEnv.
    This showed up as Trac #5795.

 compiler/rename/RnEnv.lhs    |    4 +++-
 compiler/typecheck/TcEnv.lhs |   36 ++++++++++++++++++++++++++++--------
 2 files changed, 31 insertions(+), 9 deletions(-)

comment:3 Changed 7 years ago by simonpj

Resolution: fixed
Status: newclosed
Test Case: th/T5795

Thanks. I've fixed this. Not perfectly but better

    GHC stage restriction:
      `ty' is used in a top-level splice or annotation,
      and must be imported, not defined locally
    In the expression: ty
    In the type signature for `f': f :: $ty
Note: See TracTickets for help on using tickets.