Commit ef10d0a7 authored by simonpj@microsoft.com's avatar simonpj@microsoft.com
Browse files

Improve error message in TcHsType

Fixes Trac #863.
Test is tcfail162
parent 63739e3f
...@@ -191,8 +191,7 @@ kcHsSigType ty = kcTypeType ty ...@@ -191,8 +191,7 @@ kcHsSigType ty = kcTypeType ty
kcHsLiftedSigType ty = kcLiftedType ty kcHsLiftedSigType ty = kcLiftedType ty
tcHsKindedType :: LHsType Name -> TcM Type tcHsKindedType :: LHsType Name -> TcM Type
-- Don't do kind checking, nor validity checking, -- Don't do kind checking, nor validity checking.
-- but do hoist for-alls to the top
-- This is used in type and class decls, where kinding is -- This is used in type and class decls, where kinding is
-- done in advance, and validity checking is done later -- done in advance, and validity checking is done later
-- [Validity checking done later because of knot-tying issues.] -- [Validity checking done later because of knot-tying issues.]
...@@ -242,15 +241,23 @@ kcCheckHsType (L span ty) exp_kind ...@@ -242,15 +241,23 @@ kcCheckHsType (L span ty) exp_kind
-- because checkExpectedKind already mentions -- because checkExpectedKind already mentions
-- 'ty' by name in any error message -- 'ty' by name in any error message
; checkExpectedKind ty act_kind exp_kind ; checkExpectedKind (strip ty) act_kind exp_kind
; return (L span ty') } ; return (L span ty') }
where where
-- Wrap a context around only if we want to -- Wrap a context around only if we want to show that contexts.
-- show that contexts. Omit invisble ones -- Omit invisble ones and ones user's won't grok (HsPred p).
-- and ones user's won't grok (HsPred p). add_ctxt (HsPredTy p) thing = thing
add_ctxt (HsPredTy p) thing = thing add_ctxt (HsForAllTy Implicit tvs (L _ []) (L _ ty)) thing = add_ctxt ty thing
add_ctxt (HsForAllTy Implicit tvs (L _ []) ty) thing = thing
add_ctxt other_ty thing = addErrCtxt (typeCtxt ty) thing add_ctxt other_ty thing = addErrCtxt (typeCtxt ty) thing
-- We infer the kind of the type, and then complain if it's
-- not right. But we don't want to complain about
-- (ty) or !(ty) or forall a. ty
-- when the real difficulty is with the 'ty' part.
strip (HsParTy (L _ ty)) = strip ty
strip (HsBangTy _ (L _ ty)) = strip ty
strip (HsForAllTy _ _ _ (L _ ty)) = strip ty
strip ty = ty
\end{code} \end{code}
Here comes the main function Here comes the main function
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment