Commit b565830d authored by Simon Peyton Jones's avatar Simon Peyton Jones
Browse files

Wrap solveEqualities in checkNoErrs

This simple change fixes Trac #11563, #11520, #11516, #11399.
See esp the comments in #11520.

See Note [Fail fast on kind errors] in TcSimplify

Merge to 8.0 branch
parent a8249726
......@@ -97,11 +97,11 @@ simplifyTop wanteds
; return (evBindMapBinds binds1 `unionBags` binds2) }
-- | Type-check a thing that emits only equality constraints, then
-- solve those constraints. Emits errors -- but does not fail --
-- if there is trouble.
-- solve those constraints. Fails outright if there is trouble.
solveEqualities :: TcM a -> TcM a
solveEqualities thing_inside
= do { (result, wanted) <- captureConstraints thing_inside
= checkNoErrs $ -- See Note [Fail fast on kind errors]
do { (result, wanted) <- captureConstraints thing_inside
; traceTc "solveEqualities {" $ text "wanted = " <+> ppr wanted
; final_wc <- runTcSEqualities $ simpl_top wanted
; traceTc "End solveEqualities }" empty
......@@ -183,7 +183,23 @@ defaultCallStacks wanteds
= return (Just ct)
{-
{- Note [Fail fast on kind errors]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
solveEqualities is used to solve kind equalities when kind-checking
user-written types. If solving fails we should fail outright, rather
than just accumulate an error message, for two reasons:
* A kind-bogus type signature may cause a cascade of knock-on
errors if we let it pass
* More seriously, if we don't solve a constraint we'll be left
with a type that has a coercion hole in it, something like
<type> |> co-hole
where co-hole is not filled in. Eeek! That un-filled-in
hole actually causes GHC to crash with "fvProv falls into a hole"
See Trac #11563, #11520, #11516, #11399
So it's important to use 'checkNoErrs' here!
Note [When to do type-class defaulting]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In GHC 7.6 and 7.8.2, we did type-class defaulting only if insolubleWC
......
......@@ -275,8 +275,7 @@ kcTyClGroup (TyClGroup { group_tyclds = decls })
-- 4. Generalise the inferred kinds
-- See Note [Kind checking for type and class decls]
; lcl_env <- checkNoErrs $
solveEqualities $
; lcl_env <- solveEqualities $
do {
-- Step 1: Bind kind variables for non-synonyms
let (syn_decls, non_syn_decls) = partition (isSynDecl . unLoc) decls
......@@ -1173,8 +1172,7 @@ tcFamTyPats :: FamTyConShape
-> TcM a
tcFamTyPats fam_shape@(name,_,_) mb_clsinfo pats kind_checker thing_inside
= do { (typats, res_kind)
<- checkNoErrs $ -- we'll get duplicate errors if we continue.
solveEqualities $ -- See Note [Constraints in patterns]
<- solveEqualities $ -- See Note [Constraints in patterns]
tc_fam_ty_pats fam_shape mb_clsinfo pats kind_checker
{- TODO (RAE): This should be cleverer. Consider this:
......
{-# LANGUAGE FlexibleInstances, TypeInType #-}
module T11399 where
import Data.Kind
newtype UhOh (k :: * -> *) (a :: k *) = UhOh (k *)
instance Functor k => Functor (UhOh k) where
T11399.hs:7:32: error:
• Couldn't match kind ‘*’ with ‘GHC.Types.Levity’
When matching kinds
k :: * -> *
TYPE :: GHC.Types.Levity -> *
Expected kind ‘* -> *’, but ‘UhOh k’ has kind ‘k * -> *’
• In the first argument of ‘Functor’, namely ‘UhOh k’
In the instance declaration for ‘Functor (UhOh k)’
T11516.hs:11:16: error:
• Expected kind ‘i0 -> i0 -> *’, but ‘()’ has kind ‘*’
• In the first argument of ‘Varpi’, namely ‘()’
In the instance declaration for ‘Varpi (->) (->) (Either f)’
{-# LANGUAGE RankNTypes, PolyKinds, TypeInType, GADTs, UndecidableSuperClasses #-}
module T11520 where
import GHC.Types hiding (TyCon)
data TypeRep (a :: k)
class Typeable k => Typeable (a :: k) where
typeRep :: TypeRep a
data Compose (f :: k1 -> *) (g :: k2 -> k1) (a :: k2) = Compose (f (g a))
-- Note how the kind signature on g is incorrect
instance (Typeable f, Typeable (g :: k), Typeable k) => Typeable (Compose f g) where
typeRep = undefined
T11520.hs:15:77: error:
• Expected kind ‘k20 -> k10’, but ‘g’ has kind ‘k’
• In the second argument of ‘Compose’, namely ‘g’
In the first argument of ‘Typeable’, namely ‘Compose f g’
In the instance declaration for ‘Typeable (Compose f g)’
......@@ -137,3 +137,6 @@ test('T11466', normal, compile_fail, [''])
test('T11480a', normal, compile, [''])
test('T11480b', normal, compile, [''])
test('T11523', normal, compile, [''])
test('T11520', normal, compile_fail, [''])
test('T11516', normal, compile_fail, [''])
test('T11399', normal, compile_fail, [''])
rnfail026.hs:16:10: error:
• Illegal polymorphic type: forall a. Eq a => Set a
• In the instance declaration for ‘Monad (forall a. Eq a => Set a)’
rnfail026.hs:16:27: error:
• Expected kind ‘* -> *’, but ‘Set a’ has kind ‘*’
• In the first argument of ‘Monad’, namely
‘forall a. Eq a => Set a’
In the instance declaration for ‘Monad (forall a. Eq a => Set a)’
rnfail026.hs:19:10: error:
• Illegal polymorphic type: forall a. [a]
• In the instance declaration for ‘Eq (forall a. [a])’
rnfail026.hs:16:27: error:
• Expected kind ‘* -> *’, but ‘Set a’ has kind ‘*’
• In the first argument of ‘Monad’, namely
‘forall a. Eq a => Set a’
In the instance declaration for ‘Monad (forall a. Eq a => Set a)’
rnfail026.hs:19:10: error:
• Illegal polymorphic type: forall a. [a]
• In the instance declaration for ‘Eq (forall a. [a])’
......@@ -502,6 +502,5 @@ test('RebindHR', normal, compile, [''])
test('RebindNegate', normal, compile, [''])
test('T11397', normal, compile, [''])
test('T11458', normal, compile, [''])
test('T11516', expect_broken(11516), compile, [''])
test('T11524', normal, compile, [''])
test('T11552', normal, compile, [''])
module T11563 where
data T a = MkT
class C t
instance C s => C T
T11563.hs:5:19: error:
• Expecting one more argument to ‘T’
Expected a type, but ‘T’ has kind ‘* -> *’
• In the first argument of ‘C’, namely ‘T’
In the instance declaration for ‘C T’
T2994.hs:11:10: error:
Expecting one more argument to ‘MonadReader Int’
Expected a constraint,
but ‘MonadReader Int’ has kind ‘* -> Constraint’
In the instance declaration for ‘MonadReader Int’
T2994.hs:11:10: error:
Malformed instance head: MonadReader Int
In the instance declaration for ‘MonadReader Int’
T2994.hs:13:10: error:
Expecting one more argument to ‘MonadReader (Reader' r)’
Expected a constraint,
but ‘MonadReader (Reader' r)’ has kind ‘* -> Constraint’
In the instance declaration for ‘MonadReader (Reader' r)’
• Expecting one more argument to ‘MonadReader Int’
Expected a constraint,
but ‘MonadReader Int’ has kind ‘* -> Constraint’
• In the instance declaration for ‘MonadReader Int’
T2994.hs:13:10: error:
Malformed instance head: MonadReader (Reader' r)
In the instance declaration for ‘MonadReader (Reader' r)’
• Expecting one more argument to ‘MonadReader (Reader' r)’
Expected a constraint,
but ‘MonadReader (Reader' r)’ has kind ‘* -> Constraint’
• In the instance declaration for ‘MonadReader (Reader' r)’
T2994.hs:13:23: error:
Expecting one more argument to ‘Reader' r’
Expected a type, but ‘Reader' r’ has kind ‘* -> *’
In the first argument of ‘MonadReader’, namely ‘Reader' r’
In the instance declaration for ‘MonadReader (Reader' r)’
T2994.hs:15:10: error:
Expecting one fewer argument to ‘MonadReader r r’
Expected kind ‘(* -> *) -> Constraint’,
but ‘MonadReader r r’ has kind ‘Constraint’
In the instance declaration for ‘MonadReader r r (Reader' r)’
• Expecting one more argument to ‘Reader' r’
Expected a type, but ‘Reader' r’ has kind ‘* -> *’
• In the first argument of ‘MonadReader’, namely ‘Reader' r’
In the instance declaration for ‘MonadReader (Reader' r)’
T2994.hs:15:10: error:
Malformed instance head: MonadReader r r (Reader' r)
In the instance declaration for ‘MonadReader r r (Reader' r)’
• Expecting one fewer argument to ‘MonadReader r r’
Expected kind ‘(* -> *) -> Constraint’,
but ‘MonadReader r r’ has kind ‘Constraint’
• In the instance declaration for ‘MonadReader r r (Reader' r)’
......@@ -19,18 +19,6 @@ T3540.hs:13:12: error:
• In the type signature:
thing3 :: (?dude :: Int) -> Int
T3540.hs:16:10: error:
• Could not deduce (Eq a0)
from the context: Eq a
bound by the type signature for:
thing4 :: Eq a => Int
at T3540.hs:16:10-22
The type variable ‘a0’ is ambiguous
• In the ambiguity check for ‘thing4’
To defer the ambiguity check to use sites, enable AllowAmbiguousTypes
In the type signature:
thing4 :: (Eq a) -> Int
T3540.hs:16:11: error:
• Expected a type, but ‘Eq a’ has kind ‘Constraint’
• In the type signature:
......
......@@ -405,3 +405,4 @@ test('T11356', normal, compile_fail, [''])
test('T11355', normal, compile_fail, [''])
test('T11464', normal, compile_fail, [''])
test('T11473', expect_broken(11473), compile_fail, [''])
test('T11563', normal, compile_fail, [''])
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