Commit c64539cd authored by Simon Peyton Jones's avatar Simon Peyton Jones
Browse files

When reporting the context of given constraints, stop when you find one

that binds a variable mentioned in the wanted

There is really no point in reporting ones further out; they can't be useful
parent e840d853
......@@ -1068,7 +1068,7 @@ mk_dict_err fam_envs ctxt (ct, (matches, unifiers, safe_haskell))
add_to_ctxt_fixes has_ambig_tvs
| not has_ambig_tvs && all_tyvars
, (orig:origs) <- mapMaybe get_good_orig (cec_encl ctxt)
, (orig:origs) <- usefulContext ctxt pred
= [sep [ ptext (sLit "add") <+> pprParendType pred
<+> ptext (sLit "to the context of")
, nest 2 $ ppr_skol orig $$
......@@ -1079,11 +1079,6 @@ mk_dict_err fam_envs ctxt (ct, (matches, unifiers, safe_haskell))
ppr_skol (PatSkol dc _) = ptext (sLit "the data constructor") <+> quotes (ppr dc)
ppr_skol skol_info = ppr skol_info
-- Do not suggest adding constraints to an *inferred* type signature!
get_good_orig ic = case ic_info ic of
SigSkol (InfSigCtxt {}) _ -> Nothing
origin -> Just origin
no_inst_msg
| clas == coercibleClass
= let (ty1, ty2) = getEqPredTys pred
......@@ -1218,6 +1213,22 @@ mk_dict_err fam_envs ctxt (ct, (matches, unifiers, safe_haskell))
, ptext (sLit "is not in scope") ])
| otherwise = Nothing
usefulContext :: ReportErrCtxt -> TcPredType -> [SkolemInfo]
usefulContext ctxt pred
= go (cec_encl ctxt)
where
pred_tvs = tyVarsOfType pred
go [] = []
go (ic : ics)
= case ic_info ic of
-- Do not suggest adding constraints to an *inferred* type signature!
SigSkol (InfSigCtxt {}) _ -> rest
info -> info : rest
where
-- Stop when the context binds a variable free in the predicate
rest | any (`elemVarSet` pred_tvs) (ic_skols ic) = []
| otherwise = go ics
show_fixes :: [SDoc] -> SDoc
show_fixes [] = empty
show_fixes (f:fs) = sep [ ptext (sLit "Possible fix:")
......
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