Opened 3 years ago

Closed 3 years ago

Last modified 3 years ago

#8831 closed bug (fixed)

Cannot use Template Haskell splice in ghci

Reported by: goldfire Owned by: thoughtpolice
Priority: highest Milestone: 7.8.1
Component: Template Haskell Version: 7.8.1-rc2
Keywords: Cc: kazu@…
Operating System: MacOS X Architecture: x86_64 (amd64)
Type of failure: None/Unknown Test Case: ghci/scripts/T8831
Blocked By: Blocking:
Related Tickets: Differential Rev(s):
Wiki Page:


I have this module:

{-# LANGUAGE TemplateHaskell #-}

module A where

foo = [| 3 |]

Now, I do this in ghci:

> :seti -XTemplateHaskell
> :load A.hs
[1 of 1] Compiling A                ( A.hs, interpreted )
Ok, modules loaded: A.
> $foo
Loading package array- ... linking ... done.
Loading package deepseq- ... linking ... done.
Loading package containers- ... linking ... done.
Loading package pretty- ... linking ... done.
Loading package template-haskell ... linking ... done.
unknown package: main

The problem is the last line, failing to find the main package. I can reproduce this issue in 7.8rc1 and in HEAD.

Change History (11)

comment:1 Changed 3 years ago by simonpj

  • Milestone set to 7.8.1
  • Priority changed from normal to highest

This looks bad. When did it start to happen? I'm surprised a regression test doesn't catch it.

Austin can you investigate?


comment:2 Changed 3 years ago by thoughtpolice

  • Owner set to thoughtpolice

I'm also extremely surprised a test didn't seem to catch this. I'm looking into it.

comment:3 Changed 3 years ago by thoughtpolice

  • Version changed from 7.8.1-rc1 to 7.8.1-rc2

comment:4 Changed 3 years ago by kazu-yamamoto

  • Cc kazu@… added

comment:5 Changed 3 years ago by Austin Seipp <austin@…>

In f9b6a2bb6574904ab11476d79896491b111ad7cc/ghc:

testsuite: add test for #8831

Signed-off-by: Austin Seipp <>

comment:6 Changed 3 years ago by Joachim Breitner <mail@…>

In 4bc3c8265f988f4456664f502164f52466aab67d/ghc:

Mark test for #8831 as known-broken

to keep validate working.

comment:7 Changed 3 years ago by Simon Peyton Jones <simonpj@…>

In 28e8d878b63d06824001ac3a631254679e0f1960/ghc:

Simplify handling of the interactive package; fixes Trac #8831

This patch is really a fix to the big commint
   Re-work the naming story for the GHCi prompt (Trac #8649)
which introduced the 'interactive' package
See Note [The interactive package] in HscTypes

The original commit set both
  (a) The tcg_mod field of TcGblEnv to 'interactive:Ghci4' (say)
  (b) The thisPackage field of DynFlags to 'interactive'

But the second step interacts badly with linking.  :loaded modules are
in the package set by 'thisPackage' (usually 'main'); if you change
that, then we try to link package 'main', but can't find it, and
that is what happened in #8831.

The fix was simple: do (a) but not (b).

I changed Note [The interactive package] in HscTypes to describe this.

comment:8 Changed 3 years ago by Simon Peyton Jones <simonpj@…>

comment:9 Changed 3 years ago by simonpj

  • Status changed from new to merge
  • Test Case set to ghci/scripts/T8831

comment:10 Changed 3 years ago by thoughtpolice

  • Resolution set to fixed
  • Status changed from merge to closed


comment:11 Changed 3 years ago by kazu-yamamoto

Thanks, Simon.

I confirmed that this bug has been fixed.

Note: See TracTickets for help on using tickets.