Skip to content

Problem with Template Haskell and deriving Data for newtypes #976

@larskuhtz

Description

@larskuhtz

ghcide fails to compile modules that use TemplateHaskell and also derive Data for newtypes. Using a template Haskell expression from such a module in another module fails, even if the newtype isn't exported.

File src/A.hs:

{-# LANGUAGE DeriveDataTypeable #-}
{-# LANGUAGE TemplateHaskell #-}
module A (a) where
import Data.Data
import Language.Haskell.TH
newtype A = A () deriving (Data)
   -- if the deriving clause is removed the issue goes away

a :: ExpQ
a = [| 0 |]

File src/B.hs:

{-# LANGUAGE TemplateHaskell #-}
module B where
import A

b :: Int
b = $( a )

File: hie.yaml

cradle:
  direct:
    arguments:
      - '-isrc'

The error message in file src/B.hs is:

[typecheck] [E] Program error: 
ByteCodeLink.lookupCE
During interactive linking, GHCi couldn't find the following symbol:
  A_A_closure
This may be due to you not asking GHCi to load extra object files,
archives or DLLs needed by your current session.  Restart GHCi, specifying
the missing library using the -L/path/to/object/dir and -lmissinglibname
flags, or simply by naming the relevant files on the GHCi command line.
Alternatively, this link failure might indicate a bug in GHCi.
If you suspect the latter, please send a bug report to:
  glasgow-haskell-bugs@haskell.org

Running ghcide gives:

lars@paul:~/Code/github/ghcide/tmp (master) [GHC-8.8.1]$ ghcide
ghcide version: 0.0.6 (GHC: 8.8.1) (PATH: /Users/lars/.cabal/bin/ghcide) (GIT hash: 913aa5f9fa3508dcbe423aea3e0d0effe1b57d1b)
Ghcide setup tester in /Users/lars/Code/github/ghcide/tmp.
Report bugs at https://github.com/digital-asset/ghcide/issues

Step 1/6: Finding files to test in /Users/lars/Code/github/ghcide/tmp
Found 2 files

Step 2/6: Looking for hie.yaml files that control setup
Found 1 cradle

Step 3/6, Cradle 1/1: Loading ./hie.yaml

Step 4/6, Cradle 1/1: Loading GHC Session
Loaded package environment from /Users/lars/.ghc/x86_64-darwin-8.8.1/environments/default

Step 5/6: Initializing the IDE

Step 6/6: Type checking the files
ghcide: ^^ Could not load '_A_A_closure', dependency unresolved. See top entry above.

Files that failed:
 * ./src/B.hs

Completed (1 file worked, 1 file failed)
File:     src/B.hs
Hidden:   no
Range:    1:0-100001:0
Source:   typecheck
Severity: DsError

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions