Comments only: replace ":=:" by "~" (notation for equality predicates)
[ghc-hetmet.git] / compiler / typecheck / TcExpr.lhs
index d0052d8..6260b89 100644 (file)
@@ -85,7 +85,8 @@ tcPolyExpr expr res_ty
 tcPolyExprNC expr res_ty 
   | isSigmaTy res_ty
   = do { traceTc (text "tcPolyExprNC" <+> ppr res_ty)
-       ; (gen_fn, expr') <- tcGen res_ty emptyVarSet Nothing (tcPolyExprNC expr)
+       ; (gen_fn, expr') <- tcGen res_ty emptyVarSet Nothing $ \ _ res_ty ->
+                            tcPolyExprNC expr res_ty
                -- Note the recursive call to tcPolyExpr, because the
                -- type may have multiple layers of for-alls
                -- E.g. forall a. Eq a => forall b. Ord b => ....
@@ -200,8 +201,10 @@ tcExpr in_expr@(ExprWithTySig expr sig_ty) res_ty
  = do  { sig_tc_ty <- tcHsSigType ExprSigCtxt sig_ty
 
        -- Remember to extend the lexical type-variable environment
-       ; (gen_fn, expr') <- tcGen sig_tc_ty emptyVarSet (Just ExprSigCtxt) $
-                            tcMonoExprNC expr
+       ; (gen_fn, expr') <- tcGen sig_tc_ty emptyVarSet (Just ExprSigCtxt) $ \ skol_tvs res_ty ->
+                            tcExtendTyVarEnv2 (hsExplicitTvs sig_ty `zip` mkTyVarTys skol_tvs) $
+                               -- See Note [More instantiated than scoped] in TcBinds
+                            tcMonoExprNC expr res_ty
 
        ; co_fn <- tcSubExp ExprSigOrigin sig_tc_ty res_ty
        ; return (mkHsWrap co_fn (ExprWithTySigOut (mkLHsWrap gen_fn expr') sig_ty)) }
@@ -312,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