Give a better error message when we try to print a value of unknown type
authorSimon Marlow <simonmar@microsoft.com>
Thu, 26 Apr 2007 08:36:57 +0000 (08:36 +0000)
committerSimon Marlow <simonmar@microsoft.com>
Thu, 26 Apr 2007 08:36:57 +0000 (08:36 +0000)
  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

compiler/ghci/Debugger.hs
compiler/main/GHC.hs
compiler/typecheck/TcSimplify.lhs
compiler/typecheck/TcType.lhs

index 3174785..7459589 100644 (file)
@@ -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)
index a8c435a..ef19889 100644 (file)
@@ -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
index 911e2ff..80718b7 100644 (file)
@@ -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")
index 728f58b..caea74f 100644 (file)
@@ -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")