Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
Shayne Fletcher
Glasgow Haskell Compiler
Commits
f4742cfc
Commit
f4742cfc
authored
Mar 22, 2001
by
simonpj
Browse files
[project @ 2001-03-22 11:20:36 by simonpj]
Improve error message for ambiguity
parent
c0c4923f
Changes
1
Hide whitespace changes
Inline
Side-by-side
ghc/compiler/typecheck/TcMonoType.lhs
View file @
f4742cfc
...
...
@@ -48,7 +48,7 @@ import Type ( Type, Kind, PredType(..), ThetaType, SigmaType, TauType,
tyVarsOfType, tyVarsOfPred, mkForAllTys,
isUnboxedTupleType, isForAllTy, isIPPred
)
import PprType ( pprType, pprPred )
import PprType ( pprType,
pprTheta,
pprPred )
import Subst ( mkTopTyVarSubst, substTy )
import CoreFVs ( idFreeTyVars )
import Id ( mkLocalId, idName, idType )
...
...
@@ -565,12 +565,23 @@ checkAmbiguity wimp_out is_source_polytype forall_tyvars theta tau
tau_vars = tyVarsOfType tau
extended_tau_vars = grow theta tau_vars
-- Hack alert. If there are no tyvars, (ppr sigma_ty) will print
-- something strange like {Eq k} -> k -> k, because there is no
-- ForAll at the top of the type. Since this is going to the user
-- we want it to look like a proper Haskell type even then; hence the hack
--
-- This shows up in the complaint about
-- case C a where
-- op :: Eq a => a -> a
ppr_sigma | null forall_tyvars = pprTheta theta <+> ptext SLIT("=>") <+> ppr tau
| otherwise = ppr sigma_ty
is_ambig ct_var = (ct_var `elem` forall_tyvars) &&
not (ct_var `elemVarSet` extended_tau_vars)
is_free ct_var = not (ct_var `elem` forall_tyvars)
check_pred pred = checkTc (not any_ambig) (ambigErr pred sigma
_ty
) `thenTc_`
checkTc (isIPPred pred || not all_free) (freeErr pred sigma
_ty
)
check_pred pred = checkTc (not any_ambig) (ambigErr pred
ppr_
sigma) `thenTc_`
checkTc (isIPPred pred || not all_free) (freeErr pred
ppr_
sigma)
where
ct_vars = varSetElems (tyVarsOfPred pred)
all_free = all is_free ct_vars
...
...
@@ -965,16 +976,16 @@ wrongThingErr expected thing name
pp_thing (ATcId _) = ptext SLIT("Local identifier")
pp_thing (AThing _) = ptext SLIT("Utterly bogus")
ambigErr pred ty
ambigErr pred
ppr_
ty
= sep [ptext SLIT("Ambiguous constraint") <+> quotes (pprPred pred),
nest 4 (ptext SLIT("for the type:") <+> ppr
ty),
nest 4 (ptext SLIT("for the type:") <+> ppr
_
ty),
nest 4 (ptext SLIT("At least one of the forall'd type variables mentioned by the constraint") $$
ptext SLIT("must be reachable from the type after the =>"))]
freeErr pred ty
freeErr pred
ppr_
ty
= sep [ptext SLIT("The constraint") <+> quotes (pprPred pred) <+>
ptext SLIT("does not mention any of the universally quantified type variables"),
nest 4 (ptext SLIT("in the type") <+> quotes
(
ppr
ty)
)
nest 4 (ptext SLIT("in the type") <+> quotes ppr
_
ty)
]
polyArgTyErr ty = ptext SLIT("Illegal polymorphic type as argument:") <+> ppr ty
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment