summaryrefslogtreecommitdiff
path: root/compiler
diff options
context:
space:
mode:
authorRichard Eisenberg <eir@cis.upenn.edu>2015-02-11 13:40:21 -0500
committerRichard Eisenberg <eir@cis.upenn.edu>2015-02-11 15:30:31 -0500
commit849e25ca4bb5aac2d49d0e27a5dfba61b6f72640 (patch)
treeea2e4a1b2fc7fb062a92f7154b060e6149060f56 /compiler
parentd5cd94d7b57dc233ff40bb3e494b7baf1be4d285 (diff)
downloadhaskell-849e25ca4bb5aac2d49d0e27a5dfba61b6f72640.tar.gz
Propagate ReturnTvs in matchExpectedFunTys
This really should have done a while ago, with the ReturnTv factoring. It's surprising that I can't tickle the bug! Please merge to ghc-7.10.
Diffstat (limited to 'compiler')
-rw-r--r--compiler/typecheck/TcMType.hs5
-rw-r--r--compiler/typecheck/TcType.hs10
-rw-r--r--compiler/typecheck/TcUnify.hs18
3 files changed, 24 insertions, 9 deletions
diff --git a/compiler/typecheck/TcMType.hs b/compiler/typecheck/TcMType.hs
index 71fc8ffa33..eb302271d1 100644
--- a/compiler/typecheck/TcMType.hs
+++ b/compiler/typecheck/TcMType.hs
@@ -19,7 +19,7 @@ module TcMType (
newFlexiTyVar,
newFlexiTyVarTy, -- Kind -> TcM TcType
newFlexiTyVarTys, -- Int -> Kind -> TcM [TcType]
- newReturnTyVar,
+ newReturnTyVar, newReturnTyVarTy,
newMetaKindVar, newMetaKindVars,
mkTcTyVarName, cloneMetaTyVar,
@@ -434,6 +434,9 @@ newFlexiTyVarTys n kind = mapM newFlexiTyVarTy (nOfThem n kind)
newReturnTyVar :: Kind -> TcM TcTyVar
newReturnTyVar kind = newMetaTyVar ReturnTv kind
+newReturnTyVarTy :: Kind -> TcM TcType
+newReturnTyVarTy kind = TyVarTy <$> newReturnTyVar kind
+
tcInstTyVars :: [TKVar] -> TcM (TvSubst, [TcTyVar])
-- Instantiate with META type variables
-- Note that this works for a sequence of kind and type
diff --git a/compiler/typecheck/TcType.hs b/compiler/typecheck/TcType.hs
index 32120650c6..d6fadc70f6 100644
--- a/compiler/typecheck/TcType.hs
+++ b/compiler/typecheck/TcType.hs
@@ -34,7 +34,7 @@ module TcType (
MetaDetails(Flexi, Indirect), MetaInfo(..),
isImmutableTyVar, isSkolemTyVar, isMetaTyVar, isMetaTyVarTy, isTyVarTy,
isSigTyVar, isOverlappableTyVar, isTyConableTyVar,
- isFskTyVar, isFmvTyVar, isFlattenTyVar,
+ isFskTyVar, isFmvTyVar, isFlattenTyVar, isReturnTyVar,
isAmbiguousTyVar, metaTvRef, metaTyVarInfo,
isFlexi, isIndirect, isRuntimeUnkSkol,
isTypeVar, isKindVar,
@@ -686,7 +686,7 @@ isImmutableTyVar tv
isTyConableTyVar, isSkolemTyVar, isOverlappableTyVar,
isMetaTyVar, isAmbiguousTyVar,
- isFmvTyVar, isFskTyVar, isFlattenTyVar :: TcTyVar -> Bool
+ isFmvTyVar, isFskTyVar, isFlattenTyVar, isReturnTyVar :: TcTyVar -> Bool
isTyConableTyVar tv
-- True of a meta-type variable that can be filled in
@@ -736,6 +736,12 @@ isMetaTyVar tv
MetaTv {} -> True
_ -> False
+isReturnTyVar tv
+ = ASSERT2( isTcTyVar tv, ppr tv )
+ case tcTyVarDetails tv of
+ MetaTv { mtv_info = ReturnTv } -> True
+ _ -> False
+
-- isAmbiguousTyVar is used only when reporting type errors
-- It picks out variables that are unbound, namely meta
-- type variables and the RuntimUnk variables created by
diff --git a/compiler/typecheck/TcUnify.hs b/compiler/typecheck/TcUnify.hs
index 024d443b2c..689e6f4113 100644
--- a/compiler/typecheck/TcUnify.hs
+++ b/compiler/typecheck/TcUnify.hs
@@ -141,7 +141,7 @@ matchExpectedFunTys herald arity orig_ty
= do { cts <- readMetaTyVar tv
; case cts of
Indirect ty' -> go n_req ty'
- Flexi -> defer n_req ty }
+ Flexi -> defer n_req ty (isReturnTyVar tv) }
-- In all other cases we bale out into ordinary unification
-- However unlike the meta-tyvar case, we are sure that the
@@ -159,15 +159,21 @@ matchExpectedFunTys herald arity orig_ty
-- But in that case we add specialized type into error context
-- anyway, because it may be useful. See also Trac #9605.
go n_req ty = addErrCtxtM mk_ctxt $
- defer n_req ty
+ defer n_req ty False
------------
- defer n_req fun_ty
- = do { arg_tys <- newFlexiTyVarTys n_req openTypeKind
+ -- If we decide that a ReturnTv (see Note [ReturnTv] in TcType) should
+ -- really be a function type, then we need to allow the argument and
+ -- result types also to be ReturnTvs.
+ defer n_req fun_ty is_return
+ = do { arg_tys <- mapM new_ty_var_ty (nOfThem n_req openTypeKind)
-- See Note [Foralls to left of arrow]
- ; res_ty <- newFlexiTyVarTy openTypeKind
+ ; res_ty <- new_ty_var_ty openTypeKind
; co <- unifyType fun_ty (mkFunTys arg_tys res_ty)
; return (co, arg_tys, res_ty) }
+ where
+ new_ty_var_ty | is_return = newReturnTyVarTy
+ | otherwise = newFlexiTyVarTy
------------
mk_ctxt :: TidyEnv -> TcM (TidyEnv, MsgDoc)
@@ -992,7 +998,7 @@ checkTauTvUpdate dflags tv ty
where
details = ASSERT2( isMetaTyVar tv, ppr tv ) tcTyVarDetails tv
info = mtv_info details
- is_return_tv = case info of { ReturnTv -> True; _ -> False }
+ is_return_tv = isReturnTyVar tv
impredicative = canUnifyWithPolyType dflags details (tyVarKind tv)
defer_me :: TcType -> Bool