Commit 774f366e authored by Michael Sloan's avatar Michael Sloan Committed by Ben Gamari

Fail instead of panic-ing when qAddTopDecls has conversion error

See for an example where
GHC panics when using qAddTopDecls on [d| f = Bool |]. Instead, it
should be a normal error message, and that's what this change is for. It
does not entirely resolve Trac#14627, since "Illegal variable name:
'bool'" isn't a very good error for this cirumstance.

Test Plan: Manually tested.

Reviewers: goldfire, bgamari

Reviewed By: goldfire

Subscribers: rwbarton, thomie, carter

Differential Revision:
parent 13d40ff6
......@@ -894,7 +894,9 @@ instance TH.Quasi TcM where
l <- getSrcSpanM
let either_hval = convertToHsDecls l thds
ds <- case either_hval of
Left exn -> pprPanic "qAddTopDecls: can't convert top-level declarations" exn
Left exn -> failWithTc $
hang (text "Error in a declaration passed to addTopDecls:")
2 exn
Right ds -> return ds
mapM_ (checkTopDecl . unLoc) ds
th_topdecls_var <- fmap tcg_th_topdecls getGblEnv
{-# LANGUAGE TemplateHaskell #-}
import Language.Haskell.TH
import Language.Haskell.TH.Syntax
invalidDecl <- valD (varP (mkName "emptyDo")) (normalB (doE [])) []
addTopDecls [invalidDecl]
return [])
Error in a declaration passed to addTopDecls:
Empty stmt list in do-block
When splicing a TH declaration: emptyDo = do
......@@ -424,3 +424,4 @@ test('T9693', expect_broken(9693), ghci_script, ['T9693.script'])
test('T14471', normal, compile, [''])
test('TH_rebindableAdo', normal, compile, [''])
test('T14627', normal, compile_fail, [''])
test('TH_invalid_add_top_decl', normal, compile_fail, [''])
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment