From: Simon Marlow Date: Thu, 26 Apr 2007 08:36:57 +0000 (+0000) Subject: Give a better error message when we try to print a value of unknown type X-Git-Tag: 2007-05-06~96 X-Git-Url: http://git.megacz.com/?p=ghc-hetmet.git;a=commitdiff_plain;h=97351f5d70e2d5797a092059cb205089d55dacc6 Give a better error message when we try to print a value of unknown type Stopped at ../Test3.hs:(1,0)-(2,30) _result :: [a] [../Test3.hs:(1,0)-(2,30)] *Main> _result :1:0: Ambiguous type variable `a' in the constraint: `Show a' arising from a use of `print' at :1:0-6 Cannot resolve unkonwn runtime types: a Use :print or :force to determine these types --- diff --git a/compiler/ghci/Debugger.hs b/compiler/ghci/Debugger.hs index 3174785..7459589 100644 --- a/compiler/ghci/Debugger.hs +++ b/compiler/ghci/Debugger.hs @@ -198,4 +198,4 @@ mk_skol_ty ty | tyvars <- varSetElems (tyVarsOfType ty) , tyvars' <- map (mkTyVarTy . mk_skol_tv) tyvars = substTyWith tyvars tyvars' ty mk_skol_tv tv = mkTcTyVar (tyVarName tv) (tyVarKind tv) - (SkolemTv UnkSkol) + (SkolemTv RuntimeUnkSkol) diff --git a/compiler/main/GHC.hs b/compiler/main/GHC.hs index a8c435a..ef19889 100644 --- a/compiler/main/GHC.hs +++ b/compiler/main/GHC.hs @@ -2377,7 +2377,7 @@ skolemiseTy ty = (substTy subst ty, mkVarSet new_tyvars) skolemiseTyVar :: TyVar -> TyVar skolemiseTyVar tyvar = mkTcTyVar (tyVarName tyvar) (tyVarKind tyvar) - (SkolemTv UnkSkol) + (SkolemTv RuntimeUnkSkol) ----------------------------------------------------------------------------- -- show a module and it's source/object filenames diff --git a/compiler/typecheck/TcSimplify.lhs b/compiler/typecheck/TcSimplify.lhs index 911e2ff..80718b7 100644 --- a/compiler/typecheck/TcSimplify.lhs +++ b/compiler/typecheck/TcSimplify.lhs @@ -2650,6 +2650,10 @@ mkMonomorphismMsg tidy_env inst_tvs = findGlobals (mkVarSet inst_tvs) tidy_env `thenM` \ (tidy_env, docs) -> returnM (tidy_env, mk_msg docs) where + mk_msg _ | any isRuntimeUnk inst_tvs + = vcat [ptext SLIT("Cannot resolve unkonwn runtime types:") <+> + (pprWithCommas ppr inst_tvs), + ptext SLIT("Use :print or :force to determine these types")] mk_msg [] = ptext SLIT("Probable fix: add a type signature that fixes these type variable(s)") -- This happens in things like -- f x = show (read "foo") @@ -2658,6 +2662,11 @@ mkMonomorphismMsg tidy_env inst_tvs nest 2 (vcat docs), monomorphism_fix ] + +isRuntimeUnk :: TcTyVar -> Bool +isRuntimeUnk x | SkolemTv RuntimeUnkSkol <- tcTyVarDetails x = True + | otherwise = False + monomorphism_fix :: SDoc monomorphism_fix = ptext SLIT("Probable fix:") <+> (ptext SLIT("give these definition(s) an explicit type signature") diff --git a/compiler/typecheck/TcType.lhs b/compiler/typecheck/TcType.lhs index 728f58b..caea74f 100644 --- a/compiler/typecheck/TcType.lhs +++ b/compiler/typecheck/TcType.lhs @@ -323,6 +323,9 @@ data SkolemInfo | GenSkol [TcTyVar] -- Bound when doing a subsumption check for TcType -- (forall tvs. ty) + | RuntimeUnkSkol -- a type variable used to represent an unknown + -- runtime type (used in the GHCi debugger) + | UnkSkol -- Unhelpful info (until I improve it) ------------------------------------- @@ -447,6 +450,7 @@ pprSkolTvBinding tv ppr_details (SkolemTv info) = ppr_skol info ppr_skol UnkSkol = empty -- Unhelpful; omit + ppr_skol RuntimeUnkSkol = quotes (ppr tv) <+> ptext SLIT("is an unknown runtime type") ppr_skol info = quotes (ppr tv) <+> ptext SLIT("is bound by") <+> sep [pprSkolInfo info, nest 2 (ptext SLIT("at") <+> ppr (getSrcLoc tv))] @@ -465,6 +469,7 @@ pprSkolInfo (GenSkol tvs ty) = sep [ptext SLIT("the polymorphic type"), -- For type variables the others are dealt with by pprSkolTvBinding. -- For Insts, these cases should not happen pprSkolInfo UnkSkol = panic "UnkSkol" +pprSkolInfo RuntimeUnkSkol = panic "RuntimeUnkSkol" instance Outputable MetaDetails where ppr Flexi = ptext SLIT("Flexi")