From 5d786b6a2e591628468068265820a447e35e4cc9 Mon Sep 17 00:00:00 2001 From: "simonpj@microsoft.com" Date: Sat, 20 Sep 2008 21:20:10 +0000 Subject: [PATCH] Fix Trac #2597 (first bug): correct type checking for empty list The GHC front end never generates (ExplicitList []), but TH can. This patch makes the typechecker robust to such programs. --- compiler/typecheck/TcExpr.lhs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/compiler/typecheck/TcExpr.lhs b/compiler/typecheck/TcExpr.lhs index d7708b3..6260b89 100644 --- a/compiler/typecheck/TcExpr.lhs +++ b/compiler/typecheck/TcExpr.lhs @@ -315,9 +315,18 @@ tcExpr (HsIf pred b1 b2) res_ty tcExpr (HsDo do_or_lc stmts body _) res_ty = tcDoStmts do_or_lc stmts body res_ty -tcExpr in_expr@(ExplicitList _ exprs) res_ty -- Non-empty list +tcExpr in_expr@(ExplicitList _ exprs) res_ty = do { (elt_ty, coi) <- boxySplitListTy res_ty ; exprs' <- mapM (tc_elt elt_ty) exprs + ; when (null exprs) (zapToMonotype elt_ty >> return ()) + -- If there are no expressions in the comprehension + -- we must still fill in the box + -- + -- The GHC front end never generates an empty ExplicitList + -- (instead it generates the [] data constructor) but + -- Template Haskell might. We could fix the bit of + -- TH that generates ExplicitList, but it seems less + -- fragile to just handle the case here. ; return $ mkHsWrapCoI coi (ExplicitList elt_ty exprs') } where tc_elt elt_ty expr = tcPolyExpr expr elt_ty -- 1.7.10.4