| 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)
}
}
- loop n args_so_far (TyVarTy tv)
+ loop n args_so_far ty@(TyVarTy tv)
| isTyConableTyVar tv
= do { cts <- readMetaTyVar tv
; case cts of
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"
-- 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)
}