diff options
author | Ryan Scott <ryan.gl.scott@gmail.com> | 2017-07-28 11:35:22 -0400 |
---|---|---|
committer | Ryan Scott <ryan.gl.scott@gmail.com> | 2017-07-28 11:35:22 -0400 |
commit | d6186496d414638aa66a677bb4e555dba376ec97 (patch) | |
tree | 31359c43ad67fbc57dec45f73cf89009f2babb7a | |
parent | ad0037ea3ea0eb9e2e693fa10f2171611c4e2217 (diff) | |
download | haskell-d6186496d414638aa66a677bb4e555dba376ec97.tar.gz |
Error eagerly after renaming failures in reifyInstances
Summary:
Previously, if `reifyInstances` failed to discover a `Name` during
renaming, it would blindy charge into typechecking, at which point GHC would
become very confused at the absence of that `Name` and throw an internal error.
A simple workaround is to fail eagerly after renaming errors.
Test Plan: make test TEST=T13837
Reviewers: goldfire, austin, bgamari, simonpj
Reviewed By: simonpj
Subscribers: simonpj, rwbarton, thomie
GHC Trac Issues: #13837
Differential Revision: https://phabricator.haskell.org/D3793
-rw-r--r-- | compiler/typecheck/TcSplice.hs | 6 | ||||
-rw-r--r-- | testsuite/tests/th/T13837.hs | 10 | ||||
-rw-r--r-- | testsuite/tests/th/T13837.stderr | 10 | ||||
-rw-r--r-- | testsuite/tests/th/all.T | 1 |
4 files changed, 26 insertions, 1 deletions
diff --git a/compiler/typecheck/TcSplice.hs b/compiler/typecheck/TcSplice.hs index 824227a60c..266a4dfe3a 100644 --- a/compiler/typecheck/TcSplice.hs +++ b/compiler/typecheck/TcSplice.hs @@ -1138,7 +1138,11 @@ reifyInstances th_nm th_tys ; let tv_rdrs = freeKiTyVarsAllVars free_vars -- Rename to HsType Name ; ((tv_names, rn_ty), _fvs) - <- bindLRdrNames tv_rdrs $ \ tv_names -> + <- checkNoErrs $ -- If there are out-of-scope Names here, then we + -- must error before proceeding to typecheck the + -- renamed type, as that will result in GHC + -- internal errors (#13837). + bindLRdrNames tv_rdrs $ \ tv_names -> do { (rn_ty, fvs) <- rnLHsType doc rdr_ty ; return ((tv_names, rn_ty), fvs) } ; (_tvs, ty) diff --git a/testsuite/tests/th/T13837.hs b/testsuite/tests/th/T13837.hs new file mode 100644 index 0000000000..3d33341e4d --- /dev/null +++ b/testsuite/tests/th/T13837.hs @@ -0,0 +1,10 @@ +{-# LANGUAGE TemplateHaskell #-} +module T13837 where + +import Language.Haskell.TH.Lib +import Language.Haskell.TH.Syntax + +test_local_tyfam_expansion :: String +test_local_tyfam_expansion = + $(do fam_name <- newName "Fam" + stringE . show =<< qReifyInstances fam_name []) diff --git a/testsuite/tests/th/T13837.stderr b/testsuite/tests/th/T13837.stderr new file mode 100644 index 0000000000..53700b5a7a --- /dev/null +++ b/testsuite/tests/th/T13837.stderr @@ -0,0 +1,10 @@ + +T13837.hs:9:5: error: + • The exact Name ‘Fam’ is not in scope + Probable cause: you used a unique Template Haskell name (NameU), + perhaps via newName, but did not bind it + If that's it, then -ddump-splices might be useful + • In the argument of reifyInstances: Fam_0 + In the untyped splice: + $(do fam_name <- newName "Fam" + stringE . show =<< qReifyInstances fam_name []) diff --git a/testsuite/tests/th/all.T b/testsuite/tests/th/all.T index df31162c3e..b52042bb76 100644 --- a/testsuite/tests/th/all.T +++ b/testsuite/tests/th/all.T @@ -389,5 +389,6 @@ test('T13618', normal, compile_and_run, ['-v0']) test('T13642', normal, compile_fail, ['-v0']) test('T13781', normal, compile, ['-v0']) test('T13782', normal, compile, ['']) +test('T13837', normal, compile_fail, ['-v0 -dsuppress-uniques']) test('T13856', normal, compile, ['-v0 -ddump-splices -dsuppress-uniques']) test('T13968', normal, compile_fail, ['-v0']) |