From 3ee928b370511b9889a581e3e34ebe7ea9376004 Mon Sep 17 00:00:00 2001 From: "simonpj@microsoft.com" Date: Tue, 9 Jan 2007 13:53:14 +0000 Subject: [PATCH] Preserve rigidity for GADTs when typechecking explicit tuples --- compiler/typecheck/TcExpr.lhs | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/compiler/typecheck/TcExpr.lhs b/compiler/typecheck/TcExpr.lhs index 0ac873e..7850e7a 100644 --- a/compiler/typecheck/TcExpr.lhs +++ b/compiler/typecheck/TcExpr.lhs @@ -294,10 +294,19 @@ tcExpr in_expr@(ExplicitPArr _ exprs) res_ty -- maybe empty where tc_elt elt_ty expr = tcPolyExpr expr elt_ty +-- For tuples, take care to preserve rigidity +-- E.g. case (x,y) of .... +-- The scrutinee should have a rigid type if x,y do +-- The general scheme is the same as in tcIdApp tcExpr (ExplicitTuple exprs boxity) res_ty - = do { arg_tys <- boxySplitTyConApp (tupleTyCon boxity (length exprs)) res_ty - ; exprs' <- tcPolyExprs exprs arg_tys - ; return (ExplicitTuple exprs' boxity) } + = do { tvs <- newBoxyTyVars [argTypeKind | e <- exprs] + ; let tup_tc = tupleTyCon boxity (length exprs) + tup_res_ty = mkTyConApp tup_tc (mkTyVarTys tvs) + ; arg_tys <- preSubType tvs (mkVarSet tvs) tup_res_ty res_ty + ; exprs' <- tcPolyExprs exprs arg_tys + ; arg_tys' <- mapM refineBox arg_tys + ; co_fn <- tcFunResTy (tyConName tup_tc) (mkTyConApp tup_tc arg_tys') res_ty + ; return (mkHsWrap co_fn (ExplicitTuple exprs' boxity)) } tcExpr (HsProc pat cmd) res_ty = do { (pat', cmd') <- tcProc pat cmd res_ty -- 1.7.10.4