Opened 5 years ago

Closed 5 years ago

#10019 closed bug (fixed)

GHCi cannot reify a custom data constructor with Template Haskell on the first attempt

Reported by: RyanGlScott Owned by:
Priority: normal Milestone: 7.10.1
Component: Template Haskell Version: 7.8.4
Keywords: Cc:
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: GHC rejects valid program Test Case: th/T10019
Blocked By: Blocking:
Related Tickets: Differential Rev(s):
Wiki Page:

Description

I've uncovered an unusual bug with Template Haskell inside of GHCi. To duplicate it, load GHCi, create a data type, then attempt to reify one of its constructors. It will fail the first time, but succeed the second time.

$ ghci -XTemplateHaskell
GHCi, version 7.8.4: http://www.haskell.org/ghc/  :? for help
Loading package ghc-prim ... linking ... done.
Loading package integer-gmp ... linking ... done.
Loading package base ... linking ... done.
λ> import Language.Haskell.TH
λ> data Option a = Some a | None
λ> $(reify 'Some >>= stringE . show)
Failed to load interface for ‘Ghci1’
no package matching ‘interactive’ was found
λ> $(reify 'Some >>= stringE . show)
Loading package array-0.5.0.0 ... linking ... done.
Loading package deepseq-1.3.0.2 ... linking ... done.
Loading package containers-0.5.5.1 ... linking ... done.
Loading package pretty-1.1.1.1 ... linking ... done.
Loading package template-haskell ... linking ... done.
"DataConI Ghci1.Some (ForallT [PlainTV a_1627392303] [] (AppT (AppT ArrowT (VarT a_1627392303)) (AppT (ConT Ghci1.Option) (VarT a_1627392303)))) Ghci1.Option (Fixity 9 InfixL)"

Curiously, this doesn't happen when you reify a data constructor in base, such as Just:

$ ghci -XTemplateHaskell
GHCi, version 7.8.4: http://www.haskell.org/ghc/  :? for help
Loading package ghc-prim ... linking ... done.
Loading package integer-gmp ... linking ... done.
Loading package base ... linking ... done.
λ> import Language.Haskell.TH
λ> $(reify 'Just >>= stringE . show)
Loading package array-0.5.0.0 ... linking ... done.
Loading package deepseq-1.3.0.2 ... linking ... done.
Loading package containers-0.5.5.1 ... linking ... done.
Loading package pretty-1.1.1.1 ... linking ... done.
Loading package template-haskell ... linking ... done.
"DataConI Data.Maybe.Just (ForallT [PlainTV a_1627398816] [] (AppT (AppT ArrowT (VarT a_1627398816)) (AppT (ConT Data.Maybe.Maybe) (VarT a_1627398816)))) Data.Maybe.Maybe (Fixity 9 InfixL)"

Change History (4)

comment:1 Changed 5 years ago by Simon Peyton Jones <simonpj@…>

In 6ff3db92140e3ac8cbda50d1a4aab976350ac8c4/ghc:

nameIsLocalOrFrom should include interactive modules

The provoking cause was Trac #10019, but it revealed that nameIsLocalOrFrom
should really include all interactive modules (ones from the 'interactive'
package).  Previously we had some ad-hoc 'isInteractiveModule' tests with
some (but not all) the calls to nameIsLocalOrFrom.

See the new comments with Name.nameIsLocalOrFrom.

comment:2 Changed 5 years ago by simonpj

Status: newmerge
Test Case: th/T10019

Great report thank you.

Merge to 7.10 if poss

SImon

comment:3 Changed 5 years ago by thoughtpolice

Milestone: 7.10.1

comment:4 Changed 5 years ago by thoughtpolice

Resolution: fixed
Status: mergeclosed

Merged to ghc-7.10 (via 4e25dc631b9c26365b57d315655723f088480f7e).

Note: See TracTickets for help on using tickets.