Commit 37e74d84 authored by simonpj's avatar simonpj
Browse files

[project @ 2003-01-23 14:08:46 by simonpj]

Improve error message
parent 2119bdb8
......@@ -1953,15 +1953,23 @@ addTopInstanceErrs tidy_env tidy_dicts
addTopAmbigErrs (tidy_env, tidy_dicts)
= groupErrs report tidy_dicts
-- Divide into groups that share a common set of ambiguous tyvars
= mapM report (equivClasses cmp [(d, tvs_of d) | d <- tidy_dicts])
where
report dicts = mkMonomorphismMsg tidy_env dicts `thenM` \ (tidy_env, mono_msg) ->
addErrTcM (tidy_env, mk_msg dicts $$ mono_msg)
mk_msg dicts = addInstLoc dicts $
sep [text "Ambiguous type variable(s)" <+> pprQuotedList ambig_tvs,
nest 2 (text "in the constraint" <> plural dicts <+> pprInsts dicts)]
where
ambig_tvs = varSetElems (tyVarsOfInsts dicts)
tvs_of :: Inst -> [TcTyVar]
tvs_of d = varSetElems (tyVarsOfInst d)
cmp (_,tvs1) (_,tvs2) = tvs1 `compare` tvs2
report :: [(Inst,[TcTyVar])] -> TcM ()
report pairs@((_,tvs) : _) -- The pairs share a common set of ambiguous tyvars
= mkMonomorphismMsg tidy_env dicts `thenM` \ (tidy_env, mono_msg) ->
addErrTcM (tidy_env, msg $$ mono_msg)
where
dicts = map fst pairs
msg = sep [text "Ambiguous type variable" <> plural tvs <+>
pprQuotedList tvs <+> text "in these top-level constraint" <> plural dicts,
nest 2 (pprInstsInFull dicts)]
mkMonomorphismMsg :: TidyEnv -> [Inst] -> TcM (TidyEnv, Message)
-- There's an error with these Insts; if they have free type variables
......
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