diff options
author | Michael Sloan <mgsloan@gmail.com> | 2018-07-26 17:18:22 -0400 |
---|---|---|
committer | Ben Gamari <ben@smart-cactus.org> | 2018-07-27 11:40:43 -0400 |
commit | 774f366ebe58023fc50ba346894227b14816fe67 (patch) | |
tree | a2d37336c1d5c609d4e1d4f083d489aa85d18e28 | |
parent | 13d40ff65b4171c4f0adac10577667d05074441a (diff) | |
download | haskell-774f366ebe58023fc50ba346894227b14816fe67.tar.gz |
Fail instead of panic-ing when qAddTopDecls has conversion error
See https://ghc.haskell.org/trac/ghc/ticket/14627 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: https://phabricator.haskell.org/D4914
-rw-r--r-- | compiler/typecheck/TcSplice.hs | 4 | ||||
-rw-r--r-- | testsuite/tests/th/TH_invalid_add_top_decl.hs | 8 | ||||
-rw-r--r-- | testsuite/tests/th/TH_invalid_add_top_decl.stderr | 5 | ||||
-rw-r--r-- | testsuite/tests/th/all.T | 1 |
4 files changed, 17 insertions, 1 deletions
diff --git a/compiler/typecheck/TcSplice.hs b/compiler/typecheck/TcSplice.hs index 31695e3a47..5e50dac3f3 100644 --- a/compiler/typecheck/TcSplice.hs +++ b/compiler/typecheck/TcSplice.hs @@ -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 diff --git a/testsuite/tests/th/TH_invalid_add_top_decl.hs b/testsuite/tests/th/TH_invalid_add_top_decl.hs new file mode 100644 index 0000000000..b13d873d96 --- /dev/null +++ b/testsuite/tests/th/TH_invalid_add_top_decl.hs @@ -0,0 +1,8 @@ +{-# LANGUAGE TemplateHaskell #-} +import Language.Haskell.TH +import Language.Haskell.TH.Syntax + +$(do + invalidDecl <- valD (varP (mkName "emptyDo")) (normalB (doE [])) [] + addTopDecls [invalidDecl] + return []) diff --git a/testsuite/tests/th/TH_invalid_add_top_decl.stderr b/testsuite/tests/th/TH_invalid_add_top_decl.stderr new file mode 100644 index 0000000000..9124c2d669 --- /dev/null +++ b/testsuite/tests/th/TH_invalid_add_top_decl.stderr @@ -0,0 +1,5 @@ + +TH_invalid_add_top_decl.hs:5:3: + Error in a declaration passed to addTopDecls: + Empty stmt list in do-block + When splicing a TH declaration: emptyDo = do diff --git a/testsuite/tests/th/all.T b/testsuite/tests/th/all.T index cd80a6c4fb..0fddd448ea 100644 --- a/testsuite/tests/th/all.T +++ b/testsuite/tests/th/all.T @@ -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, ['']) |