X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=compiler%2Ftypecheck%2FTcUnify.lhs;h=04e9379e7c0b64d9887197d80774e762f6d22dfd;hb=2e68d0410f319a99f3f36c5e9d9be656ca10dc70;hp=6b8f2b37aeae8c19572176426d462ac2966fb6f1;hpb=e86da1bb671f77ec08d400a2a6569b6ee7a805ef;p=ghc-hetmet.git diff --git a/compiler/typecheck/TcUnify.lhs b/compiler/typecheck/TcUnify.lhs index 6b8f2b3..04e9379 100644 --- a/compiler/typecheck/TcUnify.lhs +++ b/compiler/typecheck/TcUnify.lhs @@ -148,7 +148,8 @@ subFunTys error_herald n_pats res_ty thing_inside | isOpenSynTyCon tc = do { (coi1, ty') <- tcNormaliseFamInst ty ; case coi1 of - IdCo -> defer -- no progress, but maybe solvable => defer + IdCo -> defer n args_so_far ty + -- no progress, but maybe solvable => defer ACo _ -> -- progress: so lets try again do { (co_fn, res) <- loop n args_so_far ty' ; return $ (co_fn <.> coiToHsWrapper (mkSymCoI coi1), res) @@ -171,7 +172,7 @@ subFunTys error_herald n_pats res_ty thing_inside } } - loop n args_so_far (TyVarTy tv) + loop n args_so_far ty@(TyVarTy tv) | isTyConableTyVar tv = do { cts <- readMetaTyVar tv ; case cts of @@ -182,7 +183,7 @@ subFunTys error_herald n_pats res_ty thing_inside res_ty ; return (idHsWrapper, res) } } | otherwise -- defer as tyvar may be refined by equalities - = defer + = defer n args_so_far ty where mk_res_ty (res_ty' : arg_tys') = mkFunTys arg_tys' res_ty' mk_res_ty [] = panic "TcUnify.mk_res_ty1" @@ -195,12 +196,15 @@ subFunTys error_herald n_pats res_ty thing_inside -- build a template type a1 -> ... -> an -> b and defer an equality -- between that template and the expected result type res_ty; then, -- use the template to type the thing_inside - defer - = do { arg_tys <- newFlexiTyVarTys n_pats argTypeKind + defer n args_so_far ty + = do { arg_tys <- newFlexiTyVarTys n argTypeKind ; res_ty' <- newFlexiTyVarTy openTypeKind ; let fun_ty = mkFunTys arg_tys res_ty' - ; coi <- defer_unification False False fun_ty res_ty - ; res <- thing_inside arg_tys res_ty' + err = error_herald <> comma $$ + text "which does not match its type" + ; coi <- addErrCtxt err $ + defer_unification False False fun_ty ty + ; res <- thing_inside (reverse args_so_far ++ arg_tys) res_ty' ; return (coiToHsWrapper coi, res) } @@ -1749,13 +1753,9 @@ unifyForAllCtxt tvs phi1 phi2 env ----------------------- unifyMisMatch outer swapped ty1 ty2 - = do { (env, msg) <- if swapped then misMatchMsg ty2 ty1 - else misMatchMsg ty1 ty2 - - -- This is the whole point of the 'outer' stuff - ; if outer then popErrCtxt (failWithTcM (env, msg)) - else failWithTcM (env, msg) - } + | swapped = unifyMisMatch outer False ty2 ty1 + | outer = popErrCtxt $ unifyMisMatch False swapped ty1 ty2 -- This is the whole point of the 'outer' stuff + | otherwise = failWithMisMatch ty1 ty2 \end{code}