Commit 6464d377 authored by Simon Peyton Jones's avatar Simon Peyton Jones
Browse files

When quantifying associated types, we may have TyVars involved, not just TcTyVars

This required a little adjustment in zonkQuantifiedTyVars
parent 1c4e8962
......@@ -886,7 +886,7 @@ tcScopedKindVars kv_ns thing_inside
= tcExtendTyVarEnv (map mkKindSigVar kv_ns) thing_inside
tcHsTyVarBndrs :: LHsTyVarBndrs Name
-> ([TyVar] -> TcM r)
-> ([TcTyVar] -> TcM r)
-> TcM r
-- Bind the type variables to skolems, each with a meta-kind variable kind
tcHsTyVarBndrs (HsQTvs { hsq_kvs = kvs, hsq_tvs = hs_tvs }) thing_inside
......@@ -895,7 +895,7 @@ tcHsTyVarBndrs (HsQTvs { hsq_kvs = kvs, hsq_tvs = hs_tvs }) thing_inside
; traceTc "tcHsTyVarBndrs" (ppr hs_tvs $$ ppr tvs)
; tcExtendTyVarEnv tvs (thing_inside tvs) }
tcHsTyVarBndr :: LHsTyVarBndr Name -> TcM TyVar
tcHsTyVarBndr :: LHsTyVarBndr Name -> TcM TcTyVar
-- Return a type variable
-- initialised with a kind variable.
-- Typically the Kind inside the KindedTyVar will be a tyvar with a mutable kind
......@@ -907,7 +907,7 @@ tcHsTyVarBndr :: LHsTyVarBndr Name -> TcM TyVar
-- instance C (a,b) where
-- type F (a,b) c = ...
-- Here a,b will be in scope when processing the associated type instance for F.
-- See Note [Associated type tyvar names] in TyCon
-- See Note [Associated type tyvar names] in Class
tcHsTyVarBndr (L _ hs_tv)
= do { let name = hsTyVarName hs_tv
; mb_tv <- tcLookupLcl_maybe name
......@@ -915,7 +915,7 @@ tcHsTyVarBndr (L _ hs_tv)
Just (ATyVar _ tv) -> return tv ;
_ -> do
{ kind <- case hs_tv of
UserTyVar {} -> newMetaKindVar
UserTyVar {} -> newMetaKindVar
KindedTyVar _ kind -> tcLHsKind kind
; return (mkTcTyVar name kind (SkolemTv False)) } } }
......
......@@ -547,9 +547,12 @@ defaultKindVarToStar kv
zonkQuantifiedTyVars :: [TcTyVar] -> TcM [TcTyVar]
-- A kind variable k may occur *after* a tyvar mentioning k in its kind
-- Can be given a mixture of TcTyVars and TyVars, in the case of
-- associated type declarations
zonkQuantifiedTyVars tyvars
= do { let (kvs, tvs) = partition isKindVar tyvars
(meta_kvs, skolem_kvs) = partition isMetaTyVar kvs
(meta_kvs, skolem_kvs)
= partition (\kv -> isTcTyVar kv && isMetaTyVar kv) kvs
-- In the non-PolyKinds case, default the kind variables
-- to *, and zonk the tyvars as usual. Notice that this
......@@ -562,10 +565,16 @@ zonkQuantifiedTyVars tyvars
do { mapM_ defaultKindVarToStar meta_kvs
; return skolem_kvs } -- Should be empty
; mapM zonkQuantifiedTyVar (qkvs ++ tvs) }
; mapM zonk_quant (qkvs ++ tvs) }
-- Because of the order, any kind variables
-- mentioned in the kinds of the type variables refer to
-- the now-quantified versions
where
zonk_quant tkv
| isTcTyVar tkv = zonkQuantifiedTyVar tkv
| otherwise = return tkv
-- For associated types, we have the class variables
-- in scope, and they are TyVars not TcTyVars
zonkQuantifiedTyVar :: TcTyVar -> TcM TcTyVar
-- The quantified type variables often include meta type variables
......
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