diff options
author | Simon Peyton Jones <simonpj@microsoft.com> | 2015-06-26 16:00:19 +0100 |
---|---|---|
committer | Simon Peyton Jones <simonpj@microsoft.com> | 2015-06-26 17:53:33 +0100 |
commit | ceb3c8448dfba23aa98a710f846304158c1c584b (patch) | |
tree | 18f397939bdf200877cc3189ddd15dfb3d30e9a8 | |
parent | a64a26f0a1a864522937caaf68687baf1a5f9bcb (diff) | |
download | haskell-ceb3c8448dfba23aa98a710f846304158c1c584b.tar.gz |
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.
16 files changed, 138 insertions, 154 deletions
diff --git a/compiler/typecheck/TcErrors.hs b/compiler/typecheck/TcErrors.hs index 3af562be76..032af20b16 100644 --- a/compiler/typecheck/TcErrors.hs +++ b/compiler/typecheck/TcErrors.hs @@ -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] diff --git a/testsuite/tests/annotations/should_fail/annfail08.stderr b/testsuite/tests/annotations/should_fail/annfail08.stderr index 2a9980dcb6..66e9c7e29b 100644 --- a/testsuite/tests/annotations/should_fail/annfail08.stderr +++ b/testsuite/tests/annotations/should_fail/annfail08.stderr @@ -1,12 +1,10 @@ -
-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) #-} diff --git a/testsuite/tests/deriving/should_fail/drvfail007.stderr b/testsuite/tests/deriving/should_fail/drvfail007.stderr index ad43243eb0..f786f336be 100644 --- a/testsuite/tests/deriving/should_fail/drvfail007.stderr +++ b/testsuite/tests/deriving/should_fail/drvfail007.stderr @@ -1,9 +1,9 @@ -
-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) diff --git a/testsuite/tests/driver/T2182.stderr b/testsuite/tests/driver/T2182.stderr index d88f6c0057..0585e4c701 100644 --- a/testsuite/tests/driver/T2182.stderr +++ b/testsuite/tests/driver/T2182.stderr @@ -1,28 +1,24 @@ -
-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) diff --git a/testsuite/tests/ghci.debugger/scripts/break003.stderr b/testsuite/tests/ghci.debugger/scripts/break003.stderr index fee6366347..00d4237e49 100644 --- a/testsuite/tests/ghci.debugger/scripts/break003.stderr +++ b/testsuite/tests/ghci.debugger/scripts/break003.stderr @@ -1,6 +1,5 @@ -
-<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 diff --git a/testsuite/tests/ghci/scripts/Defer02.stderr b/testsuite/tests/ghci/scripts/Defer02.stderr index a3a3e9d061..b5b3373489 100644 --- a/testsuite/tests/ghci/scripts/Defer02.stderr +++ b/testsuite/tests/ghci/scripts/Defer02.stderr @@ -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) diff --git a/testsuite/tests/ghci/scripts/T2182ghci.stderr b/testsuite/tests/ghci/scripts/T2182ghci.stderr index 6a6eebded2..470e72945d 100644 --- a/testsuite/tests/ghci/scripts/T2182ghci.stderr +++ b/testsuite/tests/ghci/scripts/T2182ghci.stderr @@ -1,30 +1,25 @@ -
-<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 diff --git a/testsuite/tests/partial-sigs/should_fail/AnnotatedConstraint.stderr b/testsuite/tests/partial-sigs/should_fail/AnnotatedConstraint.stderr index ef66e7539d..979651bcea 100644 --- a/testsuite/tests/partial-sigs/should_fail/AnnotatedConstraint.stderr +++ b/testsuite/tests/partial-sigs/should_fail/AnnotatedConstraint.stderr @@ -1,7 +1,6 @@ -
-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 diff --git a/testsuite/tests/rebindable/rebindable6.stderr b/testsuite/tests/rebindable/rebindable6.stderr index 10c8f56ee3..9e3dc0a5c7 100644 --- a/testsuite/tests/rebindable/rebindable6.stderr +++ b/testsuite/tests/rebindable/rebindable6.stderr @@ -1,8 +1,8 @@ -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) diff --git a/testsuite/tests/typecheck/should_fail/T2846b.stderr b/testsuite/tests/typecheck/should_fail/T2846b.stderr index 3008346ddd..0323283477 100644 --- a/testsuite/tests/typecheck/should_fail/T2846b.stderr +++ b/testsuite/tests/typecheck/should_fail/T2846b.stderr @@ -1,7 +1,6 @@ -
-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]) diff --git a/testsuite/tests/typecheck/should_fail/T6022.stderr b/testsuite/tests/typecheck/should_fail/T6022.stderr index 7d12b8f358..a85c6289da 100644 --- a/testsuite/tests/typecheck/should_fail/T6022.stderr +++ b/testsuite/tests/typecheck/should_fail/T6022.stderr @@ -1,7 +1,6 @@ -
-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 diff --git a/testsuite/tests/typecheck/should_fail/T9858a.stderr b/testsuite/tests/typecheck/should_fail/T9858a.stderr index 61c62eaeec..a42339ed78 100644 --- a/testsuite/tests/typecheck/should_fail/T9858a.stderr +++ b/testsuite/tests/typecheck/should_fail/T9858a.stderr @@ -1,14 +1,14 @@ -
-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 diff --git a/testsuite/tests/typecheck/should_fail/T9858b.stderr b/testsuite/tests/typecheck/should_fail/T9858b.stderr index b57098e8b4..656ff53c95 100644 --- a/testsuite/tests/typecheck/should_fail/T9858b.stderr +++ b/testsuite/tests/typecheck/should_fail/T9858b.stderr @@ -1,8 +1,8 @@ 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)) diff --git a/testsuite/tests/typecheck/should_fail/T9999.stderr b/testsuite/tests/typecheck/should_fail/T9999.stderr index ae7fa28123..0defd090b0 100644 --- a/testsuite/tests/typecheck/should_fail/T9999.stderr +++ b/testsuite/tests/typecheck/should_fail/T9999.stderr @@ -1,8 +1,7 @@ -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: diff --git a/testsuite/tests/typecheck/should_fail/TcStaticPointersFail02.stderr b/testsuite/tests/typecheck/should_fail/TcStaticPointersFail02.stderr index 84e0862056..f63fb47789 100644 --- a/testsuite/tests/typecheck/should_fail/TcStaticPointersFail02.stderr +++ b/testsuite/tests/typecheck/should_fail/TcStaticPointersFail02.stderr @@ -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 diff --git a/testsuite/tests/typecheck/should_fail/tcfail046.stderr b/testsuite/tests/typecheck/should_fail/tcfail046.stderr index 1dbfdad8f3..c144130fe4 100644 --- a/testsuite/tests/typecheck/should_fail/tcfail046.stderr +++ b/testsuite/tests/typecheck/should_fail/tcfail046.stderr @@ -1,15 +1,17 @@ -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 |