reify yields the wrong type in the presence of functional dependencies
reify yields an incomplete type in the following program.
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE FunctionalDependencies #-}
module B where
import Language.Haskell.TH as TH
import Language.Haskell.TH.Syntax as TH
class C a b | a -> b where
yo :: a -> IO b
instance C Bool Int where
yo = undefined
t3 :: IO ()
t3 = do
x <- yo True
$(do addModFinalizer $ TH.reify 'x >>= runIO . print
[| return () |]
)
$ inplace/bin/ghc-stage2 B.hs -fforce-recomp
[1 of 1] Compiling B ( B.hs, B.o )
VarI x_1627401898 (VarT a_1627404604) Nothing
The problem seems to be that finalizers run before functional dependencies are considered.
Hacking ghc to run finalizers after simplifyTop produces the expected output instead:
$ inplace/bin/ghc-stage2 B.hs -fforce-recomp
[1 of 1] Compiling B ( B.hs, B.o )
VarI x_1627404863 (ConT GHC.Types.Int) Nothing
Would anyone object to running finalizers after simplifyTop? This implies that finalizers shouldn't add definitions (with addTopDecls) which depend on simplifyTop to be type-checked.
Another option is to call simplifyTop before and after running finalizers. But is it safe to do so?
Trac metadata
| Trac field | Value |
|---|---|
| Version | 8.0.1 |
| Type | Bug |
| TypeOfFailure | OtherFailure |
| Priority | normal |
| Resolution | Unresolved |
| Component | Compiler |
| Test case | |
| Differential revisions | |
| BlockedBy | |
| Related | |
| Blocking | |
| CC | goldfire, mboes, simonpj |
| Operating system | |
| Architecture |
Edited by Facundo Domínguez