Commit 97351f5d authored by Simon Marlow's avatar Simon Marlow

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
  
  <interactive>:1:0:
      Ambiguous type variable `a' in the constraint:
        `Show a' arising from a use of `print' at <interactive>:1:0-6
      Cannot resolve unkonwn runtime types: a
      Use :print or :force to determine these types
parent 3432f617
......@@ -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)
......@@ -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
......
......@@ -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")
......
......@@ -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")
......
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