Commit ceb3c844 authored by Simon Peyton Jones's avatar Simon Peyton Jones

Improve error message for Typeable k (T k)

GHC can't yest build a TypeRep for a type involving kind variables.
(We await kinds = types for that.)  But the error message was terrible,
as fixing #10524 reminded me.

This improves it a lot.
parent a64a26f0
......@@ -27,6 +27,8 @@ import DataCon
import TcEvidence
import Name
import RdrName ( lookupGRE_Name, GlobalRdrEnv, mkRdrUnqual )
import Class( className )
import PrelNames( typeableClassName )
import Id
import Var
import VarSet
......@@ -1342,6 +1344,7 @@ mk_dict_err ctxt (ct, (matches, unifiers, unsafe_overlapped))
cannot_resolve_msg ct binds_msg
= vcat [ addArising orig no_inst_msg
, nest 2 extra_note
, vcat (pp_givens givens)
, ppWhen (has_ambig_tvs && not (null unifiers && null givens))
(vcat [ ambig_msg, binds_msg, potential_msg ])
......@@ -1376,22 +1379,19 @@ mk_dict_err ctxt (ct, (matches, unifiers, unsafe_overlapped))
ppr_skol skol_info = ppr skol_info
no_inst_msg
| null givens && null matches
= ptext (sLit "No instance for")
<+> pprParendType pred
$$ if type_has_arrow pred
then nest 2 $ ptext (sLit "(maybe you haven't applied a function to enough arguments?)")
else empty
| otherwise
= ptext (sLit "Could not deduce") <+> pprParendType pred
type_has_arrow (TyVarTy _) = False
type_has_arrow (AppTy t1 t2) = type_has_arrow t1 || type_has_arrow t2
type_has_arrow (TyConApp _ ts) = or $ map type_has_arrow ts
type_has_arrow (FunTy _ _) = True
type_has_arrow (ForAllTy _ t) = type_has_arrow t
type_has_arrow (LitTy _) = False
| null givens && null matches = ptext (sLit "No instance for") <+> pprParendType pred
| otherwise = ptext (sLit "Could not deduce") <+> pprParendType pred
extra_note | any isFunTy (filterOut isKind tys)
= ptext (sLit "(maybe you haven't applied a function to enough arguments?)")
| className clas == typeableClassName -- Avoid mysterious "No instance for (Typeable T)
, [_,ty] <- tys -- Look for (Typeable (k->*) (T k))
, Just (tc,_) <- tcSplitTyConApp_maybe ty
, not (isTypeFamilyTyCon tc)
= hang (ptext (sLit "GHC can't yet do polykinded"))
2 (ptext (sLit "Typeable") <+> parens (ppr ty <+> dcolon <+> ppr (typeKind ty)))
| otherwise
= empty
drv_fixes = case orig of
DerivOrigin -> [drv_fix]
......
annfail08.hs:9:1:
No instance for (Data (a0 -> a0))
(maybe you haven't applied a function to enough arguments?)
arising from an annotation
In the annotation: {-# ANN f (id + 1) #-}
annfail08.hs:9:15:
No instance for (Num (a0 -> a0))
(maybe you haven't applied a function to enough arguments?)
arising from a use of ‘+’
In the annotation: {-# ANN f (id + 1) #-}
annfail08.hs:9:1: error:
No instance for (Data (a0 -> a0)) arising from an annotation
(maybe you haven't applied a function to enough arguments?)
In the annotation: {-# ANN f (id + 1) #-}
annfail08.hs:9:15: error:
No instance for (Num (a0 -> a0)) arising from a use of ‘+’
(maybe you haven't applied a function to enough arguments?)
In the annotation: {-# ANN f (id + 1) #-}
drvfail007.hs:4:38:
No instance for (Eq (Int -> Int))
(maybe you haven't applied a function to enough arguments?)
arising from the first field of ‘Foo’ (type ‘Int -> Int’)
Possible fix:
use a standalone 'deriving instance' declaration,
so you can specify the instance context yourself
When deriving the instance for (Eq Foo)
drvfail007.hs:4:38: error:
No instance for (Eq (Int -> Int))
arising from the first field of ‘Foo’ (type ‘Int -> Int’)
(maybe you haven't applied a function to enough arguments?)
Possible fix:
use a standalone 'deriving instance' declaration,
so you can specify the instance context yourself
When deriving the instance for (Eq Foo)
T2182.hs:5:5:
No instance for (Show (t1 -> t1))
(maybe you haven't applied a function to enough arguments?)
arising from a use of ‘show’
In the expression: show (\ x -> x)
In an equation for ‘y’: y = show (\ x -> x)
T2182.hs:6:15:
No instance for (Eq (t0 -> t0))
(maybe you haven't applied a function to enough arguments?)
arising from a use of ‘==’
In the expression: (\ x -> x) == (\ y -> y)
In an equation for ‘z’: z = (\ x -> x) == (\ y -> y)
T2182.hs:5:5:
No instance for (Show (t1 -> t1))
(maybe you haven't applied a function to enough arguments?)
arising from a use of ‘show’
In the expression: show (\ x -> x)
In an equation for ‘y’: y = show (\ x -> x)
T2182.hs:6:15:
No instance for (Eq (t0 -> t0))
(maybe you haven't applied a function to enough arguments?)
arising from a use of ‘==’
In the expression: (\ x -> x) == (\ y -> y)
In an equation for ‘z’: z = (\ x -> x) == (\ y -> y)
T2182.hs:5:5: error:
No instance for (Show (t1 -> t1)) arising from a use of ‘show’
(maybe you haven't applied a function to enough arguments?)
In the expression: show (\ x -> x)
In an equation for ‘y’: y = show (\ x -> x)
T2182.hs:6:15: error:
No instance for (Eq (t0 -> t0)) arising from a use of ‘==’
(maybe you haven't applied a function to enough arguments?)
In the expression: (\ x -> x) == (\ y -> y)
In an equation for ‘z’: z = (\ x -> x) == (\ y -> y)
T2182.hs:5:5: error:
No instance for (Show (t1 -> t1)) arising from a use of ‘show’
(maybe you haven't applied a function to enough arguments?)
In the expression: show (\ x -> x)
In an equation for ‘y’: y = show (\ x -> x)
T2182.hs:6:15: error:
No instance for (Eq (t0 -> t0)) arising from a use of ‘==’
(maybe you haven't applied a function to enough arguments?)
In the expression: (\ x -> x) == (\ y -> y)
In an equation for ‘z’: z = (\ x -> x) == (\ y -> y)
<interactive>:5:1:
No instance for (Show (t -> t1))
(maybe you haven't applied a function to enough arguments?)
arising from a use of ‘print’
In a stmt of an interactive GHCi command: print it
<interactive>:5:1: error:
No instance for (Show (t -> t1)) arising from a use of ‘print’
(maybe you haven't applied a function to enough arguments?)
In a stmt of an interactive GHCi command: print it
......@@ -26,9 +26,8 @@
In an equation for ‘c’: c (C2 x) = True
../../typecheck/should_run/Defer01.hs:28:5: warning:
No instance for (Num (a -> a))
No instance for (Num (a -> a)) arising from the literal ‘1’
(maybe you haven't applied a function to enough arguments?)
arising from the literal ‘1’
In the expression: 1
In an equation for ‘d’: d = 1
......@@ -136,9 +135,8 @@
In the first argument of ‘c’, namely ‘(C2 True)’
In the first argument of ‘print’, namely ‘(c (C2 True))’
*** Exception: ../../typecheck/should_run/Defer01.hs:28:5: error:
No instance for (Num (a -> a))
No instance for (Num (a -> a)) arising from the literal ‘1’
(maybe you haven't applied a function to enough arguments?)
arising from the literal ‘1’
In the expression: 1
In an equation for ‘d’: d = 1
(deferred type error)
......
<interactive>:3:1:
No instance for (Show (t0 -> t0))
(maybe you haven't applied a function to enough arguments?)
arising from a use of ‘print’
In a stmt of an interactive GHCi command: print it
<interactive>:11:1:
No instance for (Show (t0 -> t0))
(maybe you haven't applied a function to enough arguments?)
arising from a use of ‘print’
In a stmt of an interactive GHCi command: print it
<interactive>:20:1:
No instance for (Show (t0 -> t0))
(maybe you haven't applied a function to enough arguments?)
arising from a use of ‘print’
In a stmt of an interactive GHCi command: print it
<interactive>:29:1:
No instance for (Show (t0 -> t0))
(maybe you haven't applied a function to enough arguments?)
arising from a use of ‘print’
In a stmt of an interactive GHCi command: print it
<interactive>:50:1:
No instance for (Show (t0 -> t0))
(maybe you haven't applied a function to enough arguments?)
arising from a use of ‘print’
In a stmt of an interactive GHCi command: print it
<interactive>:3:1: error:
No instance for (Show (t0 -> t0)) arising from a use of ‘print’
(maybe you haven't applied a function to enough arguments?)
In a stmt of an interactive GHCi command: print it
<interactive>:11:1: error:
No instance for (Show (t0 -> t0)) arising from a use of ‘print’
(maybe you haven't applied a function to enough arguments?)
In a stmt of an interactive GHCi command: print it
<interactive>:20:1: error:
No instance for (Show (t0 -> t0)) arising from a use of ‘print’
(maybe you haven't applied a function to enough arguments?)
In a stmt of an interactive GHCi command: print it
<interactive>:29:1: error:
No instance for (Show (t0 -> t0)) arising from a use of ‘print’
(maybe you haven't applied a function to enough arguments?)
In a stmt of an interactive GHCi command: print it
<interactive>:50:1: error:
No instance for (Show (t0 -> t0)) arising from a use of ‘print’
(maybe you haven't applied a function to enough arguments?)
In a stmt of an interactive GHCi command: print it
AnnotatedConstraint.hs:7:8:
No instance for (Eq (a0 -> a0))
(maybe you haven't applied a function to enough arguments?)
arising from a use of ‘foo’
In the expression: foo id
In an equation for ‘test’: test = foo id
AnnotatedConstraint.hs:7:8: error:
No instance for (Eq (a0 -> a0)) arising from a use of ‘foo’
(maybe you haven't applied a function to enough arguments?)
In the expression: foo id
In an equation for ‘test’: test = foo id
rebindable6.hs:106:17:
rebindable6.hs:106:17: error:
No instance for (HasSeq (IO a -> t0 -> IO b))
(maybe you haven't applied a function to enough arguments?)
arising from a do statement
(maybe you haven't applied a function to enough arguments?)
The type variable ‘t0’ is ambiguous
Relevant bindings include
g :: IO (Maybe b) (bound at rebindable6.hs:104:19)
......@@ -23,10 +23,10 @@ rebindable6.hs:106:17:
Just (b :: b) <- g;
return b }
rebindable6.hs:107:17:
rebindable6.hs:107:17: error:
No instance for (HasFail ([Char] -> t1))
(maybe you haven't applied a function to enough arguments?)
arising from a do statement
(maybe you haven't applied a function to enough arguments?)
The type variable ‘t1’ is ambiguous
Note: there is a potential instance available:
instance HasFail (String -> IO a)
......@@ -42,10 +42,10 @@ rebindable6.hs:107:17:
Just (b :: b) <- g;
return b }
rebindable6.hs:108:17:
rebindable6.hs:108:17: error:
No instance for (HasReturn (b -> t1))
(maybe you haven't applied a function to enough arguments?)
arising from a use of ‘return’
(maybe you haven't applied a function to enough arguments?)
The type variable ‘t1’ is ambiguous
Relevant bindings include
b :: b (bound at rebindable6.hs:107:23)
......
T2846b.hs:5:5:
No instance for (Show (Num a0 => a0))
(maybe you haven't applied a function to enough arguments?)
arising from a use of ‘show’
In the expression: show ([1, 2, 3] :: [Num a => a])
In an equation for ‘f’: f = show ([1, 2, 3] :: [Num a => a])
T2846b.hs:5:5: error:
No instance for (Show (Num a0 => a0)) arising from a use of ‘show’
(maybe you haven't applied a function to enough arguments?)
In the expression: show ([1, 2, 3] :: [Num a => a])
In an equation for ‘f’: f = show ([1, 2, 3] :: [Num a => a])
T6022.hs:3:9: error:
No instance for (Eq ([a] -> a))
(maybe you haven't applied a function to enough arguments?)
arising from a use of ‘==’
In the expression: x == head
In an equation for ‘f’: f x = x == head
T6022.hs:3:9: error:
No instance for (Eq ([a] -> a)) arising from a use of ‘==’
(maybe you haven't applied a function to enough arguments?)
In the expression: x == head
In an equation for ‘f’: f x = x == head
T9858a.hs:28:18: error:
No instance for (Typeable
((() :: Constraint, () :: Constraint) => ()))
(maybe you haven't applied a function to enough arguments?)
arising from a use of ‘cast’
In the expression: cast e
In the expression: case cast e of { Just e' -> ecast e' }
In an equation for ‘supercast’:
supercast
= case cast e of { Just e' -> ecast e' }
where
e = Refl
e :: E PX PX
T9858a.hs:28:18: error:
No instance for (Typeable
((() :: Constraint, () :: Constraint) => ()))
arising from a use of ‘cast’
(maybe you haven't applied a function to enough arguments?)
In the expression: cast e
In the expression: case cast e of { Just e' -> ecast e' }
In an equation for ‘supercast’:
supercast
= case cast e of { Just e' -> ecast e' }
where
e = Refl
e :: E PX PX
T9858b.hs:7:8: error:
No instance for (Typeable (Eq Int => Int))
(maybe you haven't applied a function to enough arguments?)
arising from a use of ‘typeRep’
(maybe you haven't applied a function to enough arguments?)
In the expression: typeRep (Proxy :: Proxy (Eq Int => Int))
In an equation for ‘test’:
test = typeRep (Proxy :: Proxy (Eq Int => Int))
T9999.hs:13:38:
No instance for (Typeable F1)
(maybe you haven't applied a function to enough arguments?)
arising from a use of ‘typeRep’
T9999.hs:13:38: error:
No instance for (Typeable F1) arising from a use of ‘typeRep’
GHC can't yet do polykinded Typeable (F1 :: k0 -> *)
In the second argument of ‘(==)’, namely
‘typeRep (Proxy :: Proxy F1)’
In the expression:
......
......@@ -7,7 +7,7 @@ TcStaticPointersFail02.hs:9:6: error:
TcStaticPointersFail02.hs:12:6: error:
No instance for (Typeable (Monad m => a -> m a))
(maybe you haven't applied a function to enough arguments?)
arising from a static form
(maybe you haven't applied a function to enough arguments?)
In the expression: static return
In an equation for ‘f2’: f2 = static return
tcfail046.hs:10:50:
tcfail046.hs:10:50: error:
No instance for (Eq (Process a))
arising from the first field of ‘Do’ (type ‘Process a’)
(maybe you haven't applied a function to enough arguments?)
Possible fix:
use a standalone 'deriving instance' declaration,
so you can specify the instance context yourself
When deriving the instance for (Eq (Continuation a))
tcfail046.hs:22:25:
tcfail046.hs:22:25: error:
No instance for (Eq (Process a))
arising from the first field of ‘Create’ (type ‘Process a’)
(maybe you haven't applied a function to enough arguments?)
Possible fix:
use a standalone 'deriving instance' declaration,
so you can specify the instance context yourself
......
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