{-# LANGUAGE CPP #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE TupleSections #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE ViewPatterns #-}
{-# OPTIONS_GHC -Wno-incomplete-uni-patterns #-}
module GHC.Tc.Gen.Pat
( tcLetPat
, newLetBndr
, LetBndrSpec(..)
, tcCheckPat, tcCheckPat_O, tcInferPat
, tcPats
, addDataConStupidTheta
, badFieldCon
, polyPatSig
)
where
#include "HsVersions.h"
import GHC.Prelude
import {-# SOURCE #-} GHC.Tc.Gen.Expr( tcSyntaxOp, tcSyntaxOpGen, tcInferSigma )
import GHC.Hs
import GHC.Tc.Utils.Zonk
import GHC.Tc.Gen.Sig( TcPragEnv, lookupPragEnv, addInlinePrags )
import GHC.Tc.Utils.Monad
import GHC.Tc.Utils.Instantiate
import GHC.Types.Id
import GHC.Types.Var
import GHC.Types.Name
import GHC.Types.Name.Reader
import GHC.Tc.Utils.Env
import GHC.Tc.Utils.TcMType
import GHC.Tc.Validity( arityErr )
import GHC.Core.TyCo.Ppr ( pprTyVars )
import GHC.Tc.Utils.TcType
import GHC.Tc.Utils.Unify
import GHC.Tc.Gen.HsType
import GHC.Builtin.Types
import GHC.Tc.Types.Evidence
import GHC.Tc.Types.Origin
import GHC.Core.TyCon
import GHC.Core.DataCon
import GHC.Core.PatSyn
import GHC.Core.ConLike
import GHC.Builtin.Names
import GHC.Types.Basic hiding (SuccessFlag(..))
import GHC.Driver.Session
import GHC.Types.SrcLoc
import GHC.Types.Var.Set
import GHC.Utils.Misc
import GHC.Utils.Outputable as Outputable
import qualified GHC.LanguageExtensions as LangExt
import Control.Arrow ( second )
import Control.Monad ( when )
import GHC.Data.List.SetOps ( getNth )
tcLetPat :: (Name -> Maybe TcId)
-> LetBndrSpec
-> LPat GhcRn -> ExpSigmaType
-> TcM a
-> TcM (LPat GhcTcId, a)
tcLetPat :: (Name -> Maybe TyVar)
-> LetBndrSpec
-> LPat GhcRn
-> ExpSigmaType
-> TcM a
-> TcM (LPat GhcTcId, a)
tcLetPat Name -> Maybe TyVar
sig_fn LetBndrSpec
no_gen LPat GhcRn
pat ExpSigmaType
pat_ty TcM a
thing_inside
= do { TcLevel
bind_lvl <- TcM TcLevel
getTcLevel
; let ctxt :: PatCtxt
ctxt = LetPat :: TcLevel -> (Name -> Maybe TyVar) -> LetBndrSpec -> PatCtxt
LetPat { pc_lvl :: TcLevel
pc_lvl = TcLevel
bind_lvl
, pc_sig_fn :: Name -> Maybe TyVar
pc_sig_fn = Name -> Maybe TyVar
sig_fn
, pc_new :: LetBndrSpec
pc_new = LetBndrSpec
no_gen }
penv :: PatEnv
penv = PE :: Bool -> PatCtxt -> CtOrigin -> PatEnv
PE { pe_lazy :: Bool
pe_lazy = Bool
True
, pe_ctxt :: PatCtxt
pe_ctxt = PatCtxt
ctxt
, pe_orig :: CtOrigin
pe_orig = CtOrigin
PatOrigin }
; ExpSigmaType -> Checker (LPat GhcRn) (LPat GhcTcId)
tc_lpat ExpSigmaType
pat_ty PatEnv
penv LPat GhcRn
pat TcM a
thing_inside }
tcPats :: HsMatchContext GhcRn
-> [LPat GhcRn]
-> [ExpSigmaType]
-> TcM a
-> TcM ([LPat GhcTcId], a)
tcPats :: HsMatchContext GhcRn
-> [LPat GhcRn]
-> [ExpSigmaType]
-> TcM a
-> TcM ([LPat GhcTcId], a)
tcPats HsMatchContext GhcRn
ctxt [LPat GhcRn]
pats [ExpSigmaType]
pat_tys TcM a
thing_inside
= [ExpSigmaType] -> Checker [LPat GhcRn] [LPat GhcTcId]
tc_lpats [ExpSigmaType]
pat_tys PatEnv
penv [LPat GhcRn]
pats TcM a
thing_inside
where
penv :: PatEnv
penv = PE :: Bool -> PatCtxt -> CtOrigin -> PatEnv
PE { pe_lazy :: Bool
pe_lazy = Bool
False, pe_ctxt :: PatCtxt
pe_ctxt = HsMatchContext GhcRn -> PatCtxt
LamPat HsMatchContext GhcRn
ctxt, pe_orig :: CtOrigin
pe_orig = CtOrigin
PatOrigin }
tcInferPat :: HsMatchContext GhcRn -> LPat GhcRn
-> TcM a
-> TcM ((LPat GhcTcId, a), TcSigmaType)
tcInferPat :: HsMatchContext GhcRn
-> LPat GhcRn -> TcM a -> TcM ((LPat GhcTcId, a), TcType)
tcInferPat HsMatchContext GhcRn
ctxt LPat GhcRn
pat TcM a
thing_inside
= (ExpSigmaType -> TcM (Located (Pat GhcTcId), a))
-> TcM ((Located (Pat GhcTcId), a), TcType)
forall a. (ExpSigmaType -> TcM a) -> TcM (a, TcType)
tcInfer ((ExpSigmaType -> TcM (Located (Pat GhcTcId), a))
-> TcM ((Located (Pat GhcTcId), a), TcType))
-> (ExpSigmaType -> TcM (Located (Pat GhcTcId), a))
-> TcM ((Located (Pat GhcTcId), a), TcType)
forall a b. (a -> b) -> a -> b
$ \ ExpSigmaType
exp_ty ->
ExpSigmaType -> Checker (LPat GhcRn) (LPat GhcTcId)
tc_lpat ExpSigmaType
exp_ty PatEnv
penv LPat GhcRn
pat TcM a
thing_inside
where
penv :: PatEnv
penv = PE :: Bool -> PatCtxt -> CtOrigin -> PatEnv
PE { pe_lazy :: Bool
pe_lazy = Bool
False, pe_ctxt :: PatCtxt
pe_ctxt = HsMatchContext GhcRn -> PatCtxt
LamPat HsMatchContext GhcRn
ctxt, pe_orig :: CtOrigin
pe_orig = CtOrigin
PatOrigin }
tcCheckPat :: HsMatchContext GhcRn
-> LPat GhcRn -> TcSigmaType
-> TcM a
-> TcM (LPat GhcTcId, a)
tcCheckPat :: HsMatchContext GhcRn
-> LPat GhcRn -> TcType -> TcM a -> TcM (LPat GhcTcId, a)
tcCheckPat HsMatchContext GhcRn
ctxt = HsMatchContext GhcRn
-> CtOrigin
-> LPat GhcRn
-> TcType
-> TcM a
-> TcM (LPat GhcTcId, a)
forall a.
HsMatchContext GhcRn
-> CtOrigin
-> LPat GhcRn
-> TcType
-> TcM a
-> TcM (LPat GhcTcId, a)
tcCheckPat_O HsMatchContext GhcRn
ctxt CtOrigin
PatOrigin
tcCheckPat_O :: HsMatchContext GhcRn
-> CtOrigin
-> LPat GhcRn -> TcSigmaType
-> TcM a
-> TcM (LPat GhcTcId, a)
tcCheckPat_O :: HsMatchContext GhcRn
-> CtOrigin
-> LPat GhcRn
-> TcType
-> TcM a
-> TcM (LPat GhcTcId, a)
tcCheckPat_O HsMatchContext GhcRn
ctxt CtOrigin
orig LPat GhcRn
pat TcType
pat_ty TcM a
thing_inside
= ExpSigmaType -> Checker (LPat GhcRn) (LPat GhcTcId)
tc_lpat (TcType -> ExpSigmaType
mkCheckExpType TcType
pat_ty) PatEnv
penv LPat GhcRn
pat TcM a
thing_inside
where
penv :: PatEnv
penv = PE :: Bool -> PatCtxt -> CtOrigin -> PatEnv
PE { pe_lazy :: Bool
pe_lazy = Bool
False, pe_ctxt :: PatCtxt
pe_ctxt = HsMatchContext GhcRn -> PatCtxt
LamPat HsMatchContext GhcRn
ctxt, pe_orig :: CtOrigin
pe_orig = CtOrigin
orig }
data PatEnv
= PE { PatEnv -> Bool
pe_lazy :: Bool
, PatEnv -> PatCtxt
pe_ctxt :: PatCtxt
, PatEnv -> CtOrigin
pe_orig :: CtOrigin
}
data PatCtxt
= LamPat
(HsMatchContext GhcRn)
| LetPat
{ PatCtxt -> TcLevel
pc_lvl :: TcLevel
, PatCtxt -> Name -> Maybe TyVar
pc_sig_fn :: Name -> Maybe TcId
, PatCtxt -> LetBndrSpec
pc_new :: LetBndrSpec
}
data LetBndrSpec
= LetLclBndr
| LetGblBndr TcPragEnv
instance Outputable LetBndrSpec where
ppr :: LetBndrSpec -> SDoc
ppr LetBndrSpec
LetLclBndr = String -> SDoc
text String
"LetLclBndr"
ppr (LetGblBndr {}) = String -> SDoc
text String
"LetGblBndr"
makeLazy :: PatEnv -> PatEnv
makeLazy :: PatEnv -> PatEnv
makeLazy PatEnv
penv = PatEnv
penv { pe_lazy :: Bool
pe_lazy = Bool
True }
inPatBind :: PatEnv -> Bool
inPatBind :: PatEnv -> Bool
inPatBind (PE { pe_ctxt :: PatEnv -> PatCtxt
pe_ctxt = LetPat {} }) = Bool
True
inPatBind (PE { pe_ctxt :: PatEnv -> PatCtxt
pe_ctxt = LamPat {} }) = Bool
False
tcPatBndr :: PatEnv -> Name -> ExpSigmaType -> TcM (HsWrapper, TcId)
tcPatBndr :: PatEnv -> Name -> ExpSigmaType -> TcM (HsWrapper, TyVar)
tcPatBndr penv :: PatEnv
penv@(PE { pe_ctxt :: PatEnv -> PatCtxt
pe_ctxt = LetPat { pc_lvl :: PatCtxt -> TcLevel
pc_lvl = TcLevel
bind_lvl
, pc_sig_fn :: PatCtxt -> Name -> Maybe TyVar
pc_sig_fn = Name -> Maybe TyVar
sig_fn
, pc_new :: PatCtxt -> LetBndrSpec
pc_new = LetBndrSpec
no_gen } })
Name
bndr_name ExpSigmaType
exp_pat_ty
| Just TyVar
bndr_id <- Name -> Maybe TyVar
sig_fn Name
bndr_name
= do { HsWrapper
wrap <- PatEnv -> ExpSigmaType -> TcType -> TcM HsWrapper
tc_sub_type PatEnv
penv ExpSigmaType
exp_pat_ty (TyVar -> TcType
idType TyVar
bndr_id)
; String -> SDoc -> TcRn ()
traceTc String
"tcPatBndr(sig)" (TyVar -> SDoc
forall a. Outputable a => a -> SDoc
External instance of the constraint type Outputable TyVar
ppr TyVar
bndr_id SDoc -> SDoc -> SDoc
$$ TcType -> SDoc
forall a. Outputable a => a -> SDoc
External instance of the constraint type Outputable TcType
ppr (TyVar -> TcType
idType TyVar
bndr_id) SDoc -> SDoc -> SDoc
$$ ExpSigmaType -> SDoc
forall a. Outputable a => a -> SDoc
External instance of the constraint type Outputable ExpSigmaType
ppr ExpSigmaType
exp_pat_ty)
; (HsWrapper, TyVar) -> TcM (HsWrapper, TyVar)
forall (m :: * -> *) a. Monad m => a -> m a
External instance of the constraint type forall m. Monad (IOEnv m)
return (HsWrapper
wrap, TyVar
bndr_id) }
| Bool
otherwise
= do { (TcCoercion
co, TcType
bndr_ty) <- case ExpSigmaType
exp_pat_ty of
Check TcType
pat_ty -> TcLevel
-> TcType -> IOEnv (Env TcGblEnv TcLclEnv) (TcCoercion, TcType)
promoteTcType TcLevel
bind_lvl TcType
pat_ty
Infer InferResult
infer_res -> ASSERT( bind_lvl == ir_lvl infer_res )
do { TcType
bndr_ty <- InferResult -> TcM TcType
inferResultToType InferResult
infer_res
; (TcCoercion, TcType)
-> IOEnv (Env TcGblEnv TcLclEnv) (TcCoercion, TcType)
forall (m :: * -> *) a. Monad m => a -> m a
External instance of the constraint type forall m. Monad (IOEnv m)
return (TcType -> TcCoercion
mkTcNomReflCo TcType
bndr_ty, TcType
bndr_ty) }
; TyVar
bndr_id <- LetBndrSpec -> Name -> TcType -> TcM TyVar
newLetBndr LetBndrSpec
no_gen Name
bndr_name TcType
bndr_ty
; String -> SDoc -> TcRn ()
traceTc String
"tcPatBndr(nosig)" ([SDoc] -> SDoc
vcat [ TcLevel -> SDoc
forall a. Outputable a => a -> SDoc
External instance of the constraint type Outputable TcLevel
ppr TcLevel
bind_lvl
, ExpSigmaType -> SDoc
forall a. Outputable a => a -> SDoc
External instance of the constraint type Outputable ExpSigmaType
ppr ExpSigmaType
exp_pat_ty, TcType -> SDoc
forall a. Outputable a => a -> SDoc
External instance of the constraint type Outputable TcType
ppr TcType
bndr_ty, TcCoercion -> SDoc
forall a. Outputable a => a -> SDoc
External instance of the constraint type Outputable TcCoercion
ppr TcCoercion
co
, TyVar -> SDoc
forall a. Outputable a => a -> SDoc
External instance of the constraint type Outputable TyVar
ppr TyVar
bndr_id ])
; (HsWrapper, TyVar) -> TcM (HsWrapper, TyVar)
forall (m :: * -> *) a. Monad m => a -> m a
External instance of the constraint type forall m. Monad (IOEnv m)
return (TcCoercion -> HsWrapper
mkWpCastN TcCoercion
co, TyVar
bndr_id) }
tcPatBndr PatEnv
_ Name
bndr_name ExpSigmaType
pat_ty
= do { TcType
pat_ty <- ExpSigmaType -> TcM TcType
expTypeToType ExpSigmaType
pat_ty
; String -> SDoc -> TcRn ()
traceTc String
"tcPatBndr(not let)" (Name -> SDoc
forall a. Outputable a => a -> SDoc
External instance of the constraint type Outputable Name
ppr Name
bndr_name SDoc -> SDoc -> SDoc
$$ TcType -> SDoc
forall a. Outputable a => a -> SDoc
External instance of the constraint type Outputable TcType
ppr TcType
pat_ty)
; (HsWrapper, TyVar) -> TcM (HsWrapper, TyVar)
forall (m :: * -> *) a. Monad m => a -> m a
External instance of the constraint type forall m. Monad (IOEnv m)
return (HsWrapper
idHsWrapper, Name -> TcType -> TyVar
mkLocalIdOrCoVar Name
bndr_name TcType
pat_ty) }
newLetBndr :: LetBndrSpec -> Name -> TcType -> TcM TcId
newLetBndr :: LetBndrSpec -> Name -> TcType -> TcM TyVar
newLetBndr LetBndrSpec
LetLclBndr Name
name TcType
ty
= do { Name
mono_name <- Name -> TcM Name
cloneLocalName Name
name
; TyVar -> TcM TyVar
forall (m :: * -> *) a. Monad m => a -> m a
External instance of the constraint type forall m. Monad (IOEnv m)
return (HasDebugCallStack => Name -> TcType -> TyVar
Name -> TcType -> TyVar
External instance of the constraint type HasDebugCallStack
mkLocalId Name
mono_name TcType
ty) }
newLetBndr (LetGblBndr TcPragEnv
prags) Name
name TcType
ty
= TyVar -> [LSig GhcRn] -> TcM TyVar
addInlinePrags (HasDebugCallStack => Name -> TcType -> TyVar
Name -> TcType -> TyVar
External instance of the constraint type HasDebugCallStack
mkLocalId Name
name TcType
ty) (TcPragEnv -> Name -> [LSig GhcRn]
lookupPragEnv TcPragEnv
prags Name
name)
tc_sub_type :: PatEnv -> ExpSigmaType -> TcSigmaType -> TcM HsWrapper
tc_sub_type :: PatEnv -> ExpSigmaType -> TcType -> TcM HsWrapper
tc_sub_type PatEnv
penv ExpSigmaType
t1 TcType
t2 = CtOrigin -> UserTypeCtxt -> ExpSigmaType -> TcType -> TcM HsWrapper
tcSubTypePat (PatEnv -> CtOrigin
pe_orig PatEnv
penv) UserTypeCtxt
GenSigCtxt ExpSigmaType
t1 TcType
t2
type Checker inp out = forall r.
PatEnv
-> inp
-> TcM r
-> TcM ( out
, r
)
tcMultiple :: Checker inp out -> Checker [inp] [out]
tcMultiple :: Checker inp out -> Checker [inp] [out]
tcMultiple Checker inp out
tc_pat PatEnv
penv [inp]
args TcM r
thing_inside
= do { [ErrCtxt]
err_ctxt <- TcM [ErrCtxt]
getErrCtxt
; let loop :: PatEnv -> [inp] -> TcM ([out], r)
loop PatEnv
_ []
= do { r
res <- TcM r
thing_inside
; ([out], r) -> TcM ([out], r)
forall (m :: * -> *) a. Monad m => a -> m a
External instance of the constraint type forall m. Monad (IOEnv m)
return ([], r
res) }
loop PatEnv
penv (inp
arg:[inp]
args)
= do { (out
p', ([out]
ps', r
res))
<- PatEnv -> inp -> TcM ([out], r) -> TcM (out, ([out], r))
Checker inp out
tc_pat PatEnv
penv inp
arg (TcM ([out], r) -> TcM (out, ([out], r)))
-> TcM ([out], r) -> TcM (out, ([out], r))
forall a b. (a -> b) -> a -> b
$
[ErrCtxt] -> TcM ([out], r) -> TcM ([out], r)
forall a. [ErrCtxt] -> TcM a -> TcM a
setErrCtxt [ErrCtxt]
err_ctxt (TcM ([out], r) -> TcM ([out], r))
-> TcM ([out], r) -> TcM ([out], r)
forall a b. (a -> b) -> a -> b
$
PatEnv -> [inp] -> TcM ([out], r)
loop PatEnv
penv [inp]
args
; ([out], r) -> TcM ([out], r)
forall (m :: * -> *) a. Monad m => a -> m a
External instance of the constraint type forall m. Monad (IOEnv m)
return (out
p'out -> [out] -> [out]
forall a. a -> [a] -> [a]
:[out]
ps', r
res) }
; PatEnv -> [inp] -> TcM ([out], r)
loop PatEnv
penv [inp]
args }
tc_lpat :: ExpSigmaType
-> Checker (LPat GhcRn) (LPat GhcTcId)
tc_lpat :: ExpSigmaType -> Checker (LPat GhcRn) (LPat GhcTcId)
tc_lpat ExpSigmaType
pat_ty PatEnv
penv (L SrcSpan
span Pat GhcRn
pat) TcM r
thing_inside
= SrcSpan
-> TcRn (Located (Pat GhcTcId), r)
-> TcRn (Located (Pat GhcTcId), r)
forall a. SrcSpan -> TcRn a -> TcRn a
setSrcSpan SrcSpan
span (TcRn (Located (Pat GhcTcId), r)
-> TcRn (Located (Pat GhcTcId), r))
-> TcRn (Located (Pat GhcTcId), r)
-> TcRn (Located (Pat GhcTcId), r)
forall a b. (a -> b) -> a -> b
$
do { (Pat GhcTcId
pat', r
res) <- Pat GhcRn
-> (TcM r -> TcM (Pat GhcTcId, r)) -> TcM r -> TcM (Pat GhcTcId, r)
forall a b. Pat GhcRn -> (TcM a -> TcM b) -> TcM a -> TcM b
maybeWrapPatCtxt Pat GhcRn
pat (ExpSigmaType -> Checker (Pat GhcRn) (Pat GhcTcId)
tc_pat ExpSigmaType
pat_ty PatEnv
penv Pat GhcRn
pat)
TcM r
thing_inside
; (Located (Pat GhcTcId), r) -> TcRn (Located (Pat GhcTcId), r)
forall (m :: * -> *) a. Monad m => a -> m a
External instance of the constraint type forall m. Monad (IOEnv m)
return (SrcSpan -> Pat GhcTcId -> Located (Pat GhcTcId)
forall l e. l -> e -> GenLocated l e
L SrcSpan
span Pat GhcTcId
pat', r
res) }
tc_lpats :: [ExpSigmaType]
-> Checker [LPat GhcRn] [LPat GhcTcId]
tc_lpats :: [ExpSigmaType] -> Checker [LPat GhcRn] [LPat GhcTcId]
tc_lpats [ExpSigmaType]
tys PatEnv
penv [LPat GhcRn]
pats
= ASSERT2( equalLength pats tys, ppr pats $$ ppr tys )
Checker
(GenLocated SrcSpan (Pat GhcRn), ExpSigmaType)
(Located (Pat GhcTcId))
-> Checker
[(GenLocated SrcSpan (Pat GhcRn), ExpSigmaType)]
[Located (Pat GhcTcId)]
forall inp out. Checker inp out -> Checker [inp] [out]
tcMultiple (\ PatEnv
penv' (GenLocated SrcSpan (Pat GhcRn)
p,ExpSigmaType
t) -> ExpSigmaType -> Checker (LPat GhcRn) (LPat GhcTcId)
tc_lpat ExpSigmaType
t PatEnv
penv' GenLocated SrcSpan (Pat GhcRn)
LPat GhcRn
p)
PatEnv
penv
(String
-> [GenLocated SrcSpan (Pat GhcRn)]
-> [ExpSigmaType]
-> [(GenLocated SrcSpan (Pat GhcRn), ExpSigmaType)]
forall a b. String -> [a] -> [b] -> [(a, b)]
zipEqual String
"tc_lpats" [GenLocated SrcSpan (Pat GhcRn)]
[LPat GhcRn]
pats [ExpSigmaType]
tys)
tc_pat :: ExpSigmaType
-> Checker (Pat GhcRn) (Pat GhcTcId)
tc_pat :: ExpSigmaType -> Checker (Pat GhcRn) (Pat GhcTcId)
tc_pat ExpSigmaType
pat_ty PatEnv
penv Pat GhcRn
ps_pat TcM r
thing_inside = case Pat GhcRn
ps_pat of
VarPat XVarPat GhcRn
x (L SrcSpan
l IdP GhcRn
name) -> do
{ (HsWrapper
wrap, TyVar
id) <- PatEnv -> Name -> ExpSigmaType -> TcM (HsWrapper, TyVar)
tcPatBndr PatEnv
penv Name
IdP GhcRn
name ExpSigmaType
pat_ty
; r
res <- Name -> TyVar -> TcM r -> TcM r
forall a. Name -> TyVar -> TcM a -> TcM a
tcExtendIdEnv1 Name
IdP GhcRn
name TyVar
id TcM r
thing_inside
; TcType
pat_ty <- ExpSigmaType -> TcM TcType
readExpType ExpSigmaType
pat_ty
; (Pat GhcTcId, r) -> TcM (Pat GhcTcId, r)
forall (m :: * -> *) a. Monad m => a -> m a
External instance of the constraint type forall m. Monad (IOEnv m)
return (HsWrapper -> Pat GhcTcId -> TcType -> Pat GhcTcId
mkHsWrapPat HsWrapper
wrap (XVarPat GhcTcId -> Located (IdP GhcTcId) -> Pat GhcTcId
forall p. XVarPat p -> Located (IdP p) -> Pat p
VarPat XVarPat GhcRn
XVarPat GhcTcId
x (SrcSpan -> TyVar -> GenLocated SrcSpan TyVar
forall l e. l -> e -> GenLocated l e
L SrcSpan
l TyVar
id)) TcType
pat_ty, r
res) }
ParPat XParPat GhcRn
x LPat GhcRn
pat -> do
{ (Located (Pat GhcTcId)
pat', r
res) <- ExpSigmaType -> Checker (LPat GhcRn) (LPat GhcTcId)
tc_lpat ExpSigmaType
pat_ty PatEnv
penv LPat GhcRn
pat TcM r
thing_inside
; (Pat GhcTcId, r) -> TcM (Pat GhcTcId, r)
forall (m :: * -> *) a. Monad m => a -> m a
External instance of the constraint type forall m. Monad (IOEnv m)
return (XParPat GhcTcId -> LPat GhcTcId -> Pat GhcTcId
forall p. XParPat p -> LPat p -> Pat p
ParPat XParPat GhcRn
XParPat GhcTcId
x Located (Pat GhcTcId)
LPat GhcTcId
pat', r
res) }
BangPat XBangPat GhcRn
x LPat GhcRn
pat -> do
{ (Located (Pat GhcTcId)
pat', r
res) <- ExpSigmaType -> Checker (LPat GhcRn) (LPat GhcTcId)
tc_lpat ExpSigmaType
pat_ty PatEnv
penv LPat GhcRn
pat TcM r
thing_inside
; (Pat GhcTcId, r) -> TcM (Pat GhcTcId, r)
forall (m :: * -> *) a. Monad m => a -> m a
External instance of the constraint type forall m. Monad (IOEnv m)
return (XBangPat GhcTcId -> LPat GhcTcId -> Pat GhcTcId
forall p. XBangPat p -> LPat p -> Pat p
BangPat XBangPat GhcRn
XBangPat GhcTcId
x Located (Pat GhcTcId)
LPat GhcTcId
pat', r
res) }
LazyPat XLazyPat GhcRn
x LPat GhcRn
pat -> do
{ (Located (Pat GhcTcId)
pat', (r
res, WantedConstraints
pat_ct))
<- ExpSigmaType -> Checker (LPat GhcRn) (LPat GhcTcId)
tc_lpat ExpSigmaType
pat_ty (PatEnv -> PatEnv
makeLazy PatEnv
penv) LPat GhcRn
pat (TcM (r, WantedConstraints)
-> TcM (LPat GhcTcId, (r, WantedConstraints)))
-> TcM (r, WantedConstraints)
-> TcM (LPat GhcTcId, (r, WantedConstraints))
forall a b. (a -> b) -> a -> b
$
TcM r -> TcM (r, WantedConstraints)
forall a. TcM a -> TcM (a, WantedConstraints)
captureConstraints TcM r
thing_inside
; WantedConstraints -> TcRn ()
emitConstraints WantedConstraints
pat_ct
; TcType
pat_ty <- ExpSigmaType -> TcM TcType
readExpType ExpSigmaType
pat_ty
; TcCoercion
_ <- Maybe (HsExpr GhcRn) -> TcType -> TcType -> TcM TcCoercion
unifyType Maybe (HsExpr GhcRn)
forall a. Maybe a
Nothing (HasDebugCallStack => TcType -> TcType
TcType -> TcType
External instance of the constraint type HasDebugCallStack
tcTypeKind TcType
pat_ty) TcType
liftedTypeKind
; (Pat GhcTcId, r) -> TcM (Pat GhcTcId, r)
forall (m :: * -> *) a. Monad m => a -> m a
External instance of the constraint type forall m. Monad (IOEnv m)
return (XLazyPat GhcTcId -> LPat GhcTcId -> Pat GhcTcId
forall p. XLazyPat p -> LPat p -> Pat p
LazyPat XLazyPat GhcRn
XLazyPat GhcTcId
x Located (Pat GhcTcId)
LPat GhcTcId
pat', r
res) }
WildPat XWildPat GhcRn
_ -> do
{ r
res <- TcM r
thing_inside
; TcType
pat_ty <- ExpSigmaType -> TcM TcType
expTypeToType ExpSigmaType
pat_ty
; (Pat GhcTcId, r) -> TcM (Pat GhcTcId, r)
forall (m :: * -> *) a. Monad m => a -> m a
External instance of the constraint type forall m. Monad (IOEnv m)
return (XWildPat GhcTcId -> Pat GhcTcId
forall p. XWildPat p -> Pat p
WildPat TcType
XWildPat GhcTcId
pat_ty, r
res) }
AsPat XAsPat GhcRn
x (L SrcSpan
nm_loc IdP GhcRn
name) LPat GhcRn
pat -> do
{ (HsWrapper
wrap, TyVar
bndr_id) <- SrcSpan -> TcM (HsWrapper, TyVar) -> TcM (HsWrapper, TyVar)
forall a. SrcSpan -> TcRn a -> TcRn a
setSrcSpan SrcSpan
nm_loc (PatEnv -> Name -> ExpSigmaType -> TcM (HsWrapper, TyVar)
tcPatBndr PatEnv
penv Name
IdP GhcRn
name ExpSigmaType
pat_ty)
; (Located (Pat GhcTcId)
pat', r
res) <- Name
-> TyVar
-> IOEnv (Env TcGblEnv TcLclEnv) (Located (Pat GhcTcId), r)
-> IOEnv (Env TcGblEnv TcLclEnv) (Located (Pat GhcTcId), r)
forall a. Name -> TyVar -> TcM a -> TcM a
tcExtendIdEnv1 Name
IdP GhcRn
name TyVar
bndr_id (IOEnv (Env TcGblEnv TcLclEnv) (Located (Pat GhcTcId), r)
-> IOEnv (Env TcGblEnv TcLclEnv) (Located (Pat GhcTcId), r))
-> IOEnv (Env TcGblEnv TcLclEnv) (Located (Pat GhcTcId), r)
-> IOEnv (Env TcGblEnv TcLclEnv) (Located (Pat GhcTcId), r)
forall a b. (a -> b) -> a -> b
$
ExpSigmaType -> Checker (LPat GhcRn) (LPat GhcTcId)
tc_lpat (TcType -> ExpSigmaType
mkCheckExpType (TcType -> ExpSigmaType) -> TcType -> ExpSigmaType
forall a b. (a -> b) -> a -> b
$ TyVar -> TcType
idType TyVar
bndr_id)
PatEnv
penv LPat GhcRn
pat TcM r
thing_inside
; TcType
pat_ty <- ExpSigmaType -> TcM TcType
readExpType ExpSigmaType
pat_ty
; (Pat GhcTcId, r) -> TcM (Pat GhcTcId, r)
forall (m :: * -> *) a. Monad m => a -> m a
External instance of the constraint type forall m. Monad (IOEnv m)
return (HsWrapper -> Pat GhcTcId -> TcType -> Pat GhcTcId
mkHsWrapPat HsWrapper
wrap (XAsPat GhcTcId
-> Located (IdP GhcTcId) -> LPat GhcTcId -> Pat GhcTcId
forall p. XAsPat p -> Located (IdP p) -> LPat p -> Pat p
AsPat XAsPat GhcRn
XAsPat GhcTcId
x (SrcSpan -> TyVar -> GenLocated SrcSpan TyVar
forall l e. l -> e -> GenLocated l e
L SrcSpan
nm_loc TyVar
bndr_id) Located (Pat GhcTcId)
LPat GhcTcId
pat') TcType
pat_ty,
r
res) }
ViewPat XViewPat GhcRn
_ LHsExpr GhcRn
expr LPat GhcRn
pat -> do
{
; (LHsExpr GhcTcId
expr',TcType
expr_ty) <- LHsExpr GhcRn -> TcM (LHsExpr GhcTcId, TcType)
tcInferSigma LHsExpr GhcRn
expr
; let expr_orig :: CtOrigin
expr_orig = LHsExpr GhcRn -> CtOrigin
lexprCtOrigin LHsExpr GhcRn
expr
herald :: SDoc
herald = String -> SDoc
text String
"A view pattern expression expects"
; (HsWrapper
expr_wrap1, [TcType
inf_arg_ty], TcType
inf_res_ty)
<- SDoc
-> CtOrigin
-> Maybe (HsExpr GhcRn)
-> Int
-> TcType
-> TcM (HsWrapper, [TcType], TcType)
matchActualFunTys SDoc
herald CtOrigin
expr_orig (HsExpr GhcRn -> Maybe (HsExpr GhcRn)
forall a. a -> Maybe a
Just (LHsExpr GhcRn -> HsExpr GhcRn
forall l e. GenLocated l e -> e
unLoc LHsExpr GhcRn
expr)) Int
1 TcType
expr_ty
; HsWrapper
expr_wrap2 <- PatEnv -> ExpSigmaType -> TcType -> TcM HsWrapper
tc_sub_type PatEnv
penv ExpSigmaType
pat_ty TcType
inf_arg_ty
; (Located (Pat GhcTcId)
pat', r
res) <- ExpSigmaType -> Checker (LPat GhcRn) (LPat GhcTcId)
tc_lpat (TcType -> ExpSigmaType
mkCheckExpType TcType
inf_res_ty) PatEnv
penv LPat GhcRn
pat TcM r
thing_inside
; TcType
pat_ty <- ExpSigmaType -> TcM TcType
readExpType ExpSigmaType
pat_ty
; let expr_wrap2' :: HsWrapper
expr_wrap2' = HsWrapper -> HsWrapper -> TcType -> TcType -> SDoc -> HsWrapper
mkWpFun HsWrapper
expr_wrap2 HsWrapper
idHsWrapper
TcType
pat_ty TcType
inf_res_ty SDoc
doc
expr_wrap :: HsWrapper
expr_wrap = HsWrapper
expr_wrap2' HsWrapper -> HsWrapper -> HsWrapper
<.> HsWrapper
expr_wrap1
doc :: SDoc
doc = String -> SDoc
text String
"When checking the view pattern function:" SDoc -> SDoc -> SDoc
<+> (LHsExpr GhcRn -> SDoc
forall a. Outputable a => a -> SDoc
External instance of the constraint type forall l e.
(Outputable l, Outputable e) =>
Outputable (GenLocated l e)
External instance of the constraint type Outputable SrcSpan
External instance of the constraint type forall (p :: Pass).
OutputableBndrId p =>
Outputable (HsExpr (GhcPass p))
External instance of the constraint type OutputableBndr Name
External instance of the constraint type OutputableBndr Name
External instance of the constraint type IsPass 'Renamed
ppr LHsExpr GhcRn
expr)
; (Pat GhcTcId, r) -> TcM (Pat GhcTcId, r)
forall (m :: * -> *) a. Monad m => a -> m a
External instance of the constraint type forall m. Monad (IOEnv m)
return (XViewPat GhcTcId -> LHsExpr GhcTcId -> LPat GhcTcId -> Pat GhcTcId
forall p. XViewPat p -> LHsExpr p -> LPat p -> Pat p
ViewPat TcType
XViewPat GhcTcId
pat_ty (HsWrapper -> LHsExpr GhcTcId -> LHsExpr GhcTcId
mkLHsWrap HsWrapper
expr_wrap LHsExpr GhcTcId
expr') Located (Pat GhcTcId)
LPat GhcTcId
pat', r
res)}
SigPat XSigPat GhcRn
_ LPat GhcRn
pat HsPatSigType (NoGhcTc GhcRn)
sig_ty -> do
{ (TcType
inner_ty, [(Name, TyVar)]
tv_binds, [(Name, TyVar)]
wcs, HsWrapper
wrap) <- Bool
-> HsPatSigType GhcRn
-> ExpSigmaType
-> TcM (TcType, [(Name, TyVar)], [(Name, TyVar)], HsWrapper)
tcPatSig (PatEnv -> Bool
inPatBind PatEnv
penv)
HsPatSigType (NoGhcTc GhcRn)
HsPatSigType GhcRn
sig_ty ExpSigmaType
pat_ty
; (Located (Pat GhcTcId)
pat', r
res) <- [(Name, TyVar)]
-> IOEnv (Env TcGblEnv TcLclEnv) (Located (Pat GhcTcId), r)
-> IOEnv (Env TcGblEnv TcLclEnv) (Located (Pat GhcTcId), r)
forall r. [(Name, TyVar)] -> TcM r -> TcM r
tcExtendNameTyVarEnv [(Name, TyVar)]
wcs (IOEnv (Env TcGblEnv TcLclEnv) (Located (Pat GhcTcId), r)
-> IOEnv (Env TcGblEnv TcLclEnv) (Located (Pat GhcTcId), r))
-> IOEnv (Env TcGblEnv TcLclEnv) (Located (Pat GhcTcId), r)
-> IOEnv (Env TcGblEnv TcLclEnv) (Located (Pat GhcTcId), r)
forall a b. (a -> b) -> a -> b
$
[(Name, TyVar)]
-> IOEnv (Env TcGblEnv TcLclEnv) (Located (Pat GhcTcId), r)
-> IOEnv (Env TcGblEnv TcLclEnv) (Located (Pat GhcTcId), r)
forall r. [(Name, TyVar)] -> TcM r -> TcM r
tcExtendNameTyVarEnv [(Name, TyVar)]
tv_binds (IOEnv (Env TcGblEnv TcLclEnv) (Located (Pat GhcTcId), r)
-> IOEnv (Env TcGblEnv TcLclEnv) (Located (Pat GhcTcId), r))
-> IOEnv (Env TcGblEnv TcLclEnv) (Located (Pat GhcTcId), r)
-> IOEnv (Env TcGblEnv TcLclEnv) (Located (Pat GhcTcId), r)
forall a b. (a -> b) -> a -> b
$
ExpSigmaType -> Checker (LPat GhcRn) (LPat GhcTcId)
tc_lpat (TcType -> ExpSigmaType
mkCheckExpType TcType
inner_ty) PatEnv
penv LPat GhcRn
pat TcM r
thing_inside
; TcType
pat_ty <- ExpSigmaType -> TcM TcType
readExpType ExpSigmaType
pat_ty
; (Pat GhcTcId, r) -> TcM (Pat GhcTcId, r)
forall (m :: * -> *) a. Monad m => a -> m a
External instance of the constraint type forall m. Monad (IOEnv m)
return (HsWrapper -> Pat GhcTcId -> TcType -> Pat GhcTcId
mkHsWrapPat HsWrapper
wrap (XSigPat GhcTcId
-> LPat GhcTcId -> HsPatSigType (NoGhcTc GhcTcId) -> Pat GhcTcId
forall p. XSigPat p -> LPat p -> HsPatSigType (NoGhcTc p) -> Pat p
SigPat TcType
XSigPat GhcTcId
inner_ty Located (Pat GhcTcId)
LPat GhcTcId
pat' HsPatSigType (NoGhcTc GhcRn)
HsPatSigType (NoGhcTc GhcTcId)
sig_ty) TcType
pat_ty, r
res) }
ListPat Maybe SyntaxExprRn
XListPat GhcRn
Nothing [LPat GhcRn]
pats -> do
{ (HsWrapper
coi, TcType
elt_ty) <- (TcType -> IOEnv (Env TcGblEnv TcLclEnv) (TcCoercion, TcType))
-> PatEnv -> ExpSigmaType -> TcM (HsWrapper, TcType)
forall a.
(TcType -> TcM (TcCoercion, a))
-> PatEnv -> ExpSigmaType -> TcM (HsWrapper, a)
matchExpectedPatTy TcType -> IOEnv (Env TcGblEnv TcLclEnv) (TcCoercion, TcType)
matchExpectedListTy PatEnv
penv ExpSigmaType
pat_ty
; ([Located (Pat GhcTcId)]
pats', r
res) <- Checker (GenLocated SrcSpan (Pat GhcRn)) (Located (Pat GhcTcId))
-> Checker [GenLocated SrcSpan (Pat GhcRn)] [Located (Pat GhcTcId)]
forall inp out. Checker inp out -> Checker [inp] [out]
tcMultiple (ExpSigmaType
-> PatEnv -> LPat GhcRn -> TcM r -> TcM (LPat GhcTcId, r)
ExpSigmaType -> Checker (LPat GhcRn) (LPat GhcTcId)
tc_lpat (ExpSigmaType
-> PatEnv -> LPat GhcRn -> TcM r -> TcM (LPat GhcTcId, r))
-> ExpSigmaType
-> PatEnv
-> LPat GhcRn
-> TcM r
-> TcM (LPat GhcTcId, r)
forall a b. (a -> b) -> a -> b
$ TcType -> ExpSigmaType
mkCheckExpType TcType
elt_ty)
PatEnv
penv [GenLocated SrcSpan (Pat GhcRn)]
[LPat GhcRn]
pats TcM r
thing_inside
; TcType
pat_ty <- ExpSigmaType -> TcM TcType
readExpType ExpSigmaType
pat_ty
; (Pat GhcTcId, r) -> TcM (Pat GhcTcId, r)
forall (m :: * -> *) a. Monad m => a -> m a
External instance of the constraint type forall m. Monad (IOEnv m)
return (HsWrapper -> Pat GhcTcId -> TcType -> Pat GhcTcId
mkHsWrapPat HsWrapper
coi
(XListPat GhcTcId -> [LPat GhcTcId] -> Pat GhcTcId
forall p. XListPat p -> [LPat p] -> Pat p
ListPat (TcType -> Maybe (TcType, SyntaxExpr GhcTcId) -> ListPatTc
ListPatTc TcType
elt_ty Maybe (TcType, SyntaxExpr GhcTcId)
forall a. Maybe a
Nothing) [Located (Pat GhcTcId)]
[LPat GhcTcId]
pats') TcType
pat_ty, r
res)
}
ListPat (Just SyntaxExprRn
e) [LPat GhcRn]
pats -> do
{ TcType
tau_pat_ty <- ExpSigmaType -> TcM TcType
expTypeToType ExpSigmaType
pat_ty
; (([Located (Pat GhcTcId)]
pats', r
res, TcType
elt_ty), SyntaxExprTc
e')
<- CtOrigin
-> SyntaxExprRn
-> [SyntaxOpType]
-> SyntaxOpType
-> ([TcType] -> TcM ([Located (Pat GhcTcId)], r, TcType))
-> TcM (([Located (Pat GhcTcId)], r, TcType), SyntaxExprTc)
forall a.
CtOrigin
-> SyntaxExprRn
-> [SyntaxOpType]
-> SyntaxOpType
-> ([TcType] -> TcM a)
-> TcM (a, SyntaxExprTc)
tcSyntaxOpGen CtOrigin
ListOrigin SyntaxExprRn
e [ExpSigmaType -> SyntaxOpType
SynType (TcType -> ExpSigmaType
mkCheckExpType TcType
tau_pat_ty)]
SyntaxOpType
SynList (([TcType] -> TcM ([Located (Pat GhcTcId)], r, TcType))
-> TcM (([Located (Pat GhcTcId)], r, TcType), SyntaxExprTc))
-> ([TcType] -> TcM ([Located (Pat GhcTcId)], r, TcType))
-> TcM (([Located (Pat GhcTcId)], r, TcType), SyntaxExprTc)
forall a b. (a -> b) -> a -> b
$
\ [TcType
elt_ty] ->
do { ([Located (Pat GhcTcId)]
pats', r
res) <- Checker (GenLocated SrcSpan (Pat GhcRn)) (Located (Pat GhcTcId))
-> Checker [GenLocated SrcSpan (Pat GhcRn)] [Located (Pat GhcTcId)]
forall inp out. Checker inp out -> Checker [inp] [out]
tcMultiple (ExpSigmaType
-> PatEnv -> LPat GhcRn -> TcM r -> TcM (LPat GhcTcId, r)
ExpSigmaType -> Checker (LPat GhcRn) (LPat GhcTcId)
tc_lpat (ExpSigmaType
-> PatEnv -> LPat GhcRn -> TcM r -> TcM (LPat GhcTcId, r))
-> ExpSigmaType
-> PatEnv
-> LPat GhcRn
-> TcM r
-> TcM (LPat GhcTcId, r)
forall a b. (a -> b) -> a -> b
$ TcType -> ExpSigmaType
mkCheckExpType TcType
elt_ty)
PatEnv
penv [GenLocated SrcSpan (Pat GhcRn)]
[LPat GhcRn]
pats TcM r
thing_inside
; ([Located (Pat GhcTcId)], r, TcType)
-> TcM ([Located (Pat GhcTcId)], r, TcType)
forall (m :: * -> *) a. Monad m => a -> m a
External instance of the constraint type forall m. Monad (IOEnv m)
return ([Located (Pat GhcTcId)]
pats', r
res, TcType
elt_ty) }
; (Pat GhcTcId, r) -> TcM (Pat GhcTcId, r)
forall (m :: * -> *) a. Monad m => a -> m a
External instance of the constraint type forall m. Monad (IOEnv m)
return (XListPat GhcTcId -> [LPat GhcTcId] -> Pat GhcTcId
forall p. XListPat p -> [LPat p] -> Pat p
ListPat (TcType -> Maybe (TcType, SyntaxExpr GhcTcId) -> ListPatTc
ListPatTc TcType
elt_ty ((TcType, SyntaxExprTc) -> Maybe (TcType, SyntaxExprTc)
forall a. a -> Maybe a
Just (TcType
tau_pat_ty,SyntaxExprTc
e'))) [Located (Pat GhcTcId)]
[LPat GhcTcId]
pats', r
res)
}
TuplePat XTuplePat GhcRn
_ [LPat GhcRn]
pats Boxity
boxity -> do
{ let arity :: Int
arity = [GenLocated SrcSpan (Pat GhcRn)] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
External instance of the constraint type Foldable []
length [GenLocated SrcSpan (Pat GhcRn)]
[LPat GhcRn]
pats
tc :: TyCon
tc = Boxity -> Int -> TyCon
tupleTyCon Boxity
boxity Int
arity
; (HsWrapper
coi, [TcType]
arg_tys) <- (TcType -> TcM (TcCoercion, [TcType]))
-> PatEnv -> ExpSigmaType -> TcM (HsWrapper, [TcType])
forall a.
(TcType -> TcM (TcCoercion, a))
-> PatEnv -> ExpSigmaType -> TcM (HsWrapper, a)
matchExpectedPatTy (TyCon -> TcType -> TcM (TcCoercion, [TcType])
matchExpectedTyConApp TyCon
tc)
PatEnv
penv ExpSigmaType
pat_ty
; let con_arg_tys :: [TcType]
con_arg_tys = case Boxity
boxity of Boxity
Unboxed -> Int -> [TcType] -> [TcType]
forall a. Int -> [a] -> [a]
drop Int
arity [TcType]
arg_tys
Boxity
Boxed -> [TcType]
arg_tys
; ([Located (Pat GhcTcId)]
pats', r
res) <- [ExpSigmaType] -> Checker [LPat GhcRn] [LPat GhcTcId]
tc_lpats ((TcType -> ExpSigmaType) -> [TcType] -> [ExpSigmaType]
forall a b. (a -> b) -> [a] -> [b]
map TcType -> ExpSigmaType
mkCheckExpType [TcType]
con_arg_tys)
PatEnv
penv [LPat GhcRn]
pats TcM r
thing_inside
; DynFlags
dflags <- IOEnv (Env TcGblEnv TcLclEnv) DynFlags
forall (m :: * -> *). HasDynFlags m => m DynFlags
External instance of the constraint type forall env. ContainsDynFlags env => HasDynFlags (IOEnv env)
External instance of the constraint type forall gbl lcl. ContainsDynFlags (Env gbl lcl)
getDynFlags
; let
unmangled_result :: Pat GhcTcId
unmangled_result = XTuplePat GhcTcId -> [LPat GhcTcId] -> Boxity -> Pat GhcTcId
forall p. XTuplePat p -> [LPat p] -> Boxity -> Pat p
TuplePat [TcType]
XTuplePat GhcTcId
con_arg_tys [Located (Pat GhcTcId)]
[LPat GhcTcId]
pats' Boxity
boxity
possibly_mangled_result :: Pat GhcTcId
possibly_mangled_result
| GeneralFlag -> DynFlags -> Bool
gopt GeneralFlag
Opt_IrrefutableTuples DynFlags
dflags Bool -> Bool -> Bool
&&
Boxity -> Bool
isBoxed Boxity
boxity = XLazyPat GhcTcId -> LPat GhcTcId -> Pat GhcTcId
forall p. XLazyPat p -> LPat p -> Pat p
LazyPat XLazyPat GhcTcId
NoExtField
noExtField (Pat GhcTcId -> Located (Pat GhcTcId)
forall e. e -> Located e
noLoc Pat GhcTcId
unmangled_result)
| Bool
otherwise = Pat GhcTcId
unmangled_result
; TcType
pat_ty <- ExpSigmaType -> TcM TcType
readExpType ExpSigmaType
pat_ty
; ASSERT( con_arg_tys `equalLength` pats )
(Pat GhcTcId, r) -> TcM (Pat GhcTcId, r)
forall (m :: * -> *) a. Monad m => a -> m a
External instance of the constraint type forall m. Monad (IOEnv m)
return (HsWrapper -> Pat GhcTcId -> TcType -> Pat GhcTcId
mkHsWrapPat HsWrapper
coi Pat GhcTcId
possibly_mangled_result TcType
pat_ty, r
res)
}
SumPat XSumPat GhcRn
_ LPat GhcRn
pat Int
alt Int
arity -> do
{ let tc :: TyCon
tc = Int -> TyCon
sumTyCon Int
arity
; (HsWrapper
coi, [TcType]
arg_tys) <- (TcType -> TcM (TcCoercion, [TcType]))
-> PatEnv -> ExpSigmaType -> TcM (HsWrapper, [TcType])
forall a.
(TcType -> TcM (TcCoercion, a))
-> PatEnv -> ExpSigmaType -> TcM (HsWrapper, a)
matchExpectedPatTy (TyCon -> TcType -> TcM (TcCoercion, [TcType])
matchExpectedTyConApp TyCon
tc)
PatEnv
penv ExpSigmaType
pat_ty
;
let con_arg_tys :: [TcType]
con_arg_tys = Int -> [TcType] -> [TcType]
forall a. Int -> [a] -> [a]
drop Int
arity [TcType]
arg_tys
; (Located (Pat GhcTcId)
pat', r
res) <- ExpSigmaType -> Checker (LPat GhcRn) (LPat GhcTcId)
tc_lpat (TcType -> ExpSigmaType
mkCheckExpType ([TcType]
con_arg_tys [TcType] -> Int -> TcType
forall a. Outputable a => [a] -> Int -> a
External instance of the constraint type Outputable TcType
`getNth` (Int
alt Int -> Int -> Int
forall a. Num a => a -> a -> a
External instance of the constraint type Num Int
- Int
1)))
PatEnv
penv LPat GhcRn
pat TcM r
thing_inside
; TcType
pat_ty <- ExpSigmaType -> TcM TcType
readExpType ExpSigmaType
pat_ty
; (Pat GhcTcId, r) -> TcM (Pat GhcTcId, r)
forall (m :: * -> *) a. Monad m => a -> m a
External instance of the constraint type forall m. Monad (IOEnv m)
return (HsWrapper -> Pat GhcTcId -> TcType -> Pat GhcTcId
mkHsWrapPat HsWrapper
coi (XSumPat GhcTcId -> LPat GhcTcId -> Int -> Int -> Pat GhcTcId
forall p. XSumPat p -> LPat p -> Int -> Int -> Pat p
SumPat [TcType]
XSumPat GhcTcId
con_arg_tys Located (Pat GhcTcId)
LPat GhcTcId
pat' Int
alt Int
arity) TcType
pat_ty
, r
res)
}
ConPat XConPat GhcRn
NoExtField
NoExtField Located (ConLikeP GhcRn)
con HsConPatDetails GhcRn
arg_pats ->
PatEnv
-> Located Name
-> ExpSigmaType
-> HsConPatDetails GhcRn
-> TcM r
-> TcM (Pat GhcTcId, r)
forall a.
PatEnv
-> Located Name
-> ExpSigmaType
-> HsConPatDetails GhcRn
-> TcM a
-> TcM (Pat GhcTcId, a)
tcConPat PatEnv
penv Located Name
Located (ConLikeP GhcRn)
con ExpSigmaType
pat_ty HsConPatDetails GhcRn
arg_pats TcM r
thing_inside
LitPat XLitPat GhcRn
x HsLit GhcRn
simple_lit -> do
{ let lit_ty :: TcType
lit_ty = HsLit GhcRn -> TcType
forall (p :: Pass). HsLit (GhcPass p) -> TcType
hsLitType HsLit GhcRn
simple_lit
; HsWrapper
wrap <- PatEnv -> ExpSigmaType -> TcType -> TcM HsWrapper
tc_sub_type PatEnv
penv ExpSigmaType
pat_ty TcType
lit_ty
; r
res <- TcM r
thing_inside
; TcType
pat_ty <- ExpSigmaType -> TcM TcType
readExpType ExpSigmaType
pat_ty
; (Pat GhcTcId, r) -> TcM (Pat GhcTcId, r)
forall (m :: * -> *) a. Monad m => a -> m a
External instance of the constraint type forall m. Monad (IOEnv m)
return ( HsWrapper -> Pat GhcTcId -> TcType -> Pat GhcTcId
mkHsWrapPat HsWrapper
wrap (XLitPat GhcTcId -> HsLit GhcTcId -> Pat GhcTcId
forall p. XLitPat p -> HsLit p -> Pat p
LitPat XLitPat GhcRn
XLitPat GhcTcId
x (HsLit GhcRn -> HsLit GhcTcId
forall (p1 :: Pass) (p2 :: Pass).
HsLit (GhcPass p1) -> HsLit (GhcPass p2)
convertLit HsLit GhcRn
simple_lit)) TcType
pat_ty
, r
res) }
NPat XNPat GhcRn
_ (L SrcSpan
l HsOverLit GhcRn
over_lit) Maybe (SyntaxExpr GhcRn)
mb_neg SyntaxExpr GhcRn
eq -> do
{ let orig :: CtOrigin
orig = HsOverLit GhcRn -> CtOrigin
LiteralOrigin HsOverLit GhcRn
over_lit
; ((HsOverLit GhcTcId
lit', Maybe SyntaxExprTc
mb_neg'), SyntaxExprTc
eq')
<- CtOrigin
-> SyntaxExprRn
-> [SyntaxOpType]
-> ExpSigmaType
-> ([TcType] -> TcM (HsOverLit GhcTcId, Maybe SyntaxExprTc))
-> TcM ((HsOverLit GhcTcId, Maybe SyntaxExprTc), SyntaxExprTc)
forall a.
CtOrigin
-> SyntaxExprRn
-> [SyntaxOpType]
-> ExpSigmaType
-> ([TcType] -> TcM a)
-> TcM (a, SyntaxExprTc)
tcSyntaxOp CtOrigin
orig SyntaxExpr GhcRn
SyntaxExprRn
eq [ExpSigmaType -> SyntaxOpType
SynType ExpSigmaType
pat_ty, SyntaxOpType
SynAny]
(TcType -> ExpSigmaType
mkCheckExpType TcType
boolTy) (([TcType] -> TcM (HsOverLit GhcTcId, Maybe SyntaxExprTc))
-> TcM ((HsOverLit GhcTcId, Maybe SyntaxExprTc), SyntaxExprTc))
-> ([TcType] -> TcM (HsOverLit GhcTcId, Maybe SyntaxExprTc))
-> TcM ((HsOverLit GhcTcId, Maybe SyntaxExprTc), SyntaxExprTc)
forall a b. (a -> b) -> a -> b
$
\ [TcType
neg_lit_ty] ->
let new_over_lit :: TcType -> TcM (HsOverLit GhcTcId)
new_over_lit TcType
lit_ty = HsOverLit GhcRn -> ExpSigmaType -> TcM (HsOverLit GhcTcId)
newOverloadedLit HsOverLit GhcRn
over_lit
(TcType -> ExpSigmaType
mkCheckExpType TcType
lit_ty)
in case Maybe (SyntaxExpr GhcRn)
mb_neg of
Maybe (SyntaxExpr GhcRn)
Nothing -> (, Maybe SyntaxExprTc
forall a. Maybe a
Nothing) (HsOverLit GhcTcId -> (HsOverLit GhcTcId, Maybe SyntaxExprTc))
-> TcM (HsOverLit GhcTcId)
-> TcM (HsOverLit GhcTcId, Maybe SyntaxExprTc)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
External instance of the constraint type forall env. Functor (IOEnv env)
<$> TcType -> TcM (HsOverLit GhcTcId)
new_over_lit TcType
neg_lit_ty
Just SyntaxExpr GhcRn
neg ->
(SyntaxExprTc -> Maybe SyntaxExprTc)
-> (HsOverLit GhcTcId, SyntaxExprTc)
-> (HsOverLit GhcTcId, Maybe SyntaxExprTc)
forall (a :: * -> * -> *) b c d.
Arrow a =>
a b c -> a (d, b) (d, c)
External instance of the constraint type Arrow (->)
second SyntaxExprTc -> Maybe SyntaxExprTc
forall a. a -> Maybe a
Just ((HsOverLit GhcTcId, SyntaxExprTc)
-> (HsOverLit GhcTcId, Maybe SyntaxExprTc))
-> IOEnv (Env TcGblEnv TcLclEnv) (HsOverLit GhcTcId, SyntaxExprTc)
-> TcM (HsOverLit GhcTcId, Maybe SyntaxExprTc)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
External instance of the constraint type forall env. Functor (IOEnv env)
<$>
(CtOrigin
-> SyntaxExprRn
-> [SyntaxOpType]
-> ExpSigmaType
-> ([TcType] -> TcM (HsOverLit GhcTcId))
-> IOEnv (Env TcGblEnv TcLclEnv) (HsOverLit GhcTcId, SyntaxExprTc)
forall a.
CtOrigin
-> SyntaxExprRn
-> [SyntaxOpType]
-> ExpSigmaType
-> ([TcType] -> TcM a)
-> TcM (a, SyntaxExprTc)
tcSyntaxOp CtOrigin
orig SyntaxExpr GhcRn
SyntaxExprRn
neg [SyntaxOpType
SynRho] (TcType -> ExpSigmaType
mkCheckExpType TcType
neg_lit_ty) (([TcType] -> TcM (HsOverLit GhcTcId))
-> IOEnv (Env TcGblEnv TcLclEnv) (HsOverLit GhcTcId, SyntaxExprTc))
-> ([TcType] -> TcM (HsOverLit GhcTcId))
-> IOEnv (Env TcGblEnv TcLclEnv) (HsOverLit GhcTcId, SyntaxExprTc)
forall a b. (a -> b) -> a -> b
$
\ [TcType
lit_ty] -> TcType -> TcM (HsOverLit GhcTcId)
new_over_lit TcType
lit_ty)
; r
res <- TcM r
thing_inside
; TcType
pat_ty <- ExpSigmaType -> TcM TcType
readExpType ExpSigmaType
pat_ty
; (Pat GhcTcId, r) -> TcM (Pat GhcTcId, r)
forall (m :: * -> *) a. Monad m => a -> m a
External instance of the constraint type forall m. Monad (IOEnv m)
return (XNPat GhcTcId
-> Located (HsOverLit GhcTcId)
-> Maybe (SyntaxExpr GhcTcId)
-> SyntaxExpr GhcTcId
-> Pat GhcTcId
forall p.
XNPat p
-> Located (HsOverLit p)
-> Maybe (SyntaxExpr p)
-> SyntaxExpr p
-> Pat p
NPat TcType
XNPat GhcTcId
pat_ty (SrcSpan -> HsOverLit GhcTcId -> Located (HsOverLit GhcTcId)
forall l e. l -> e -> GenLocated l e
L SrcSpan
l HsOverLit GhcTcId
lit') Maybe (SyntaxExpr GhcTcId)
Maybe SyntaxExprTc
mb_neg' SyntaxExpr GhcTcId
SyntaxExprTc
eq', r
res) }
NPlusKPat XNPlusKPat GhcRn
_ (L SrcSpan
nm_loc IdP GhcRn
name)
(L SrcSpan
loc HsOverLit GhcRn
lit) HsOverLit GhcRn
_ SyntaxExpr GhcRn
ge SyntaxExpr GhcRn
minus -> do
{ TcType
pat_ty <- ExpSigmaType -> TcM TcType
expTypeToType ExpSigmaType
pat_ty
; let orig :: CtOrigin
orig = HsOverLit GhcRn -> CtOrigin
LiteralOrigin HsOverLit GhcRn
lit
; (HsOverLit GhcTcId
lit1', SyntaxExprTc
ge')
<- CtOrigin
-> SyntaxExprRn
-> [SyntaxOpType]
-> ExpSigmaType
-> ([TcType] -> TcM (HsOverLit GhcTcId))
-> IOEnv (Env TcGblEnv TcLclEnv) (HsOverLit GhcTcId, SyntaxExprTc)
forall a.
CtOrigin
-> SyntaxExprRn
-> [SyntaxOpType]
-> ExpSigmaType
-> ([TcType] -> TcM a)
-> TcM (a, SyntaxExprTc)
tcSyntaxOp CtOrigin
orig SyntaxExpr GhcRn
SyntaxExprRn
ge [TcType -> SyntaxOpType
synKnownType TcType
pat_ty, SyntaxOpType
SynRho]
(TcType -> ExpSigmaType
mkCheckExpType TcType
boolTy) (([TcType] -> TcM (HsOverLit GhcTcId))
-> IOEnv (Env TcGblEnv TcLclEnv) (HsOverLit GhcTcId, SyntaxExprTc))
-> ([TcType] -> TcM (HsOverLit GhcTcId))
-> IOEnv (Env TcGblEnv TcLclEnv) (HsOverLit GhcTcId, SyntaxExprTc)
forall a b. (a -> b) -> a -> b
$
\ [TcType
lit1_ty] ->
HsOverLit GhcRn -> ExpSigmaType -> TcM (HsOverLit GhcTcId)
newOverloadedLit HsOverLit GhcRn
lit (TcType -> ExpSigmaType
mkCheckExpType TcType
lit1_ty)
; ((HsOverLit GhcTcId
lit2', HsWrapper
minus_wrap, TyVar
bndr_id), SyntaxExprTc
minus')
<- CtOrigin
-> SyntaxExprRn
-> [SyntaxOpType]
-> SyntaxOpType
-> ([TcType] -> TcM (HsOverLit GhcTcId, HsWrapper, TyVar))
-> TcM ((HsOverLit GhcTcId, HsWrapper, TyVar), SyntaxExprTc)
forall a.
CtOrigin
-> SyntaxExprRn
-> [SyntaxOpType]
-> SyntaxOpType
-> ([TcType] -> TcM a)
-> TcM (a, SyntaxExprTc)
tcSyntaxOpGen CtOrigin
orig SyntaxExpr GhcRn
SyntaxExprRn
minus [TcType -> SyntaxOpType
synKnownType TcType
pat_ty, SyntaxOpType
SynRho] SyntaxOpType
SynAny (([TcType] -> TcM (HsOverLit GhcTcId, HsWrapper, TyVar))
-> TcM ((HsOverLit GhcTcId, HsWrapper, TyVar), SyntaxExprTc))
-> ([TcType] -> TcM (HsOverLit GhcTcId, HsWrapper, TyVar))
-> TcM ((HsOverLit GhcTcId, HsWrapper, TyVar), SyntaxExprTc)
forall a b. (a -> b) -> a -> b
$
\ [TcType
lit2_ty, TcType
var_ty] ->
do { HsOverLit GhcTcId
lit2' <- HsOverLit GhcRn -> ExpSigmaType -> TcM (HsOverLit GhcTcId)
newOverloadedLit HsOverLit GhcRn
lit (TcType -> ExpSigmaType
mkCheckExpType TcType
lit2_ty)
; (HsWrapper
wrap, TyVar
bndr_id) <- SrcSpan -> TcM (HsWrapper, TyVar) -> TcM (HsWrapper, TyVar)
forall a. SrcSpan -> TcRn a -> TcRn a
setSrcSpan SrcSpan
nm_loc (TcM (HsWrapper, TyVar) -> TcM (HsWrapper, TyVar))
-> TcM (HsWrapper, TyVar) -> TcM (HsWrapper, TyVar)
forall a b. (a -> b) -> a -> b
$
PatEnv -> Name -> ExpSigmaType -> TcM (HsWrapper, TyVar)
tcPatBndr PatEnv
penv Name
IdP GhcRn
name (TcType -> ExpSigmaType
mkCheckExpType TcType
var_ty)
; (HsOverLit GhcTcId, HsWrapper, TyVar)
-> TcM (HsOverLit GhcTcId, HsWrapper, TyVar)
forall (m :: * -> *) a. Monad m => a -> m a
External instance of the constraint type forall m. Monad (IOEnv m)
return (HsOverLit GhcTcId
lit2', HsWrapper
wrap, TyVar
bndr_id) }
; IOEnv (Env TcGblEnv TcLclEnv) Bool -> TcRn () -> TcRn ()
forall (m :: * -> *). Monad m => m Bool -> m () -> m ()
External instance of the constraint type forall m. Monad (IOEnv m)
unlessM (Extension -> IOEnv (Env TcGblEnv TcLclEnv) Bool
forall gbl lcl. Extension -> TcRnIf gbl lcl Bool
xoptM Extension
LangExt.RebindableSyntax) (TcRn () -> TcRn ()) -> TcRn () -> TcRn ()
forall a b. (a -> b) -> a -> b
$
do { Class
icls <- Name -> TcM Class
tcLookupClass Name
integralClassName
; CtOrigin -> [TcType] -> TcRn ()
instStupidTheta CtOrigin
orig [Class -> [TcType] -> TcType
mkClassPred Class
icls [TcType
pat_ty]] }
; r
res <- Name -> TyVar -> TcM r -> TcM r
forall a. Name -> TyVar -> TcM a -> TcM a
tcExtendIdEnv1 Name
IdP GhcRn
name TyVar
bndr_id TcM r
thing_inside
; let minus'' :: SyntaxExprTc
minus'' = case SyntaxExprTc
minus' of
SyntaxExprTc
NoSyntaxExprTc -> String -> SDoc -> SyntaxExprTc
forall a. HasCallStack => String -> SDoc -> a
pprPanic String
"tc_pat NoSyntaxExprTc" (SyntaxExprTc -> SDoc
forall a. Outputable a => a -> SDoc
External instance of the constraint type Outputable SyntaxExprTc
ppr SyntaxExprTc
minus')
SyntaxExprTc { syn_expr :: SyntaxExprTc -> HsExpr GhcTcId
syn_expr = HsExpr GhcTcId
minus'_expr
, syn_arg_wraps :: SyntaxExprTc -> [HsWrapper]
syn_arg_wraps = [HsWrapper]
minus'_arg_wraps
, syn_res_wrap :: SyntaxExprTc -> HsWrapper
syn_res_wrap = HsWrapper
minus'_res_wrap }
-> SyntaxExprTc :: HsExpr GhcTcId -> [HsWrapper] -> HsWrapper -> SyntaxExprTc
SyntaxExprTc { syn_expr :: HsExpr GhcTcId
syn_expr = HsExpr GhcTcId
minus'_expr
, syn_arg_wraps :: [HsWrapper]
syn_arg_wraps = [HsWrapper]
minus'_arg_wraps
, syn_res_wrap :: HsWrapper
syn_res_wrap = HsWrapper
minus_wrap HsWrapper -> HsWrapper -> HsWrapper
<.> HsWrapper
minus'_res_wrap }
pat' :: Pat GhcTcId
pat' = XNPlusKPat GhcTcId
-> Located (IdP GhcTcId)
-> Located (HsOverLit GhcTcId)
-> HsOverLit GhcTcId
-> SyntaxExpr GhcTcId
-> SyntaxExpr GhcTcId
-> Pat GhcTcId
forall p.
XNPlusKPat p
-> Located (IdP p)
-> Located (HsOverLit p)
-> HsOverLit p
-> SyntaxExpr p
-> SyntaxExpr p
-> Pat p
NPlusKPat TcType
XNPlusKPat GhcTcId
pat_ty (SrcSpan -> TyVar -> GenLocated SrcSpan TyVar
forall l e. l -> e -> GenLocated l e
L SrcSpan
nm_loc TyVar
bndr_id) (SrcSpan -> HsOverLit GhcTcId -> Located (HsOverLit GhcTcId)
forall l e. l -> e -> GenLocated l e
L SrcSpan
loc HsOverLit GhcTcId
lit1') HsOverLit GhcTcId
lit2'
SyntaxExpr GhcTcId
SyntaxExprTc
ge' SyntaxExpr GhcTcId
SyntaxExprTc
minus''
; (Pat GhcTcId, r) -> TcM (Pat GhcTcId, r)
forall (m :: * -> *) a. Monad m => a -> m a
External instance of the constraint type forall m. Monad (IOEnv m)
return (Pat GhcTcId
pat', r
res) }
SplicePat XSplicePat GhcRn
_ HsSplice GhcRn
splice -> case HsSplice GhcRn
splice of
(HsSpliced XSpliced GhcRn
_ ThModFinalizers
mod_finalizers (HsSplicedPat Pat GhcRn
pat)) -> do
{ ThModFinalizers -> TcRn ()
addModFinalizersWithLclEnv ThModFinalizers
mod_finalizers
; ExpSigmaType -> Checker (Pat GhcRn) (Pat GhcTcId)
tc_pat ExpSigmaType
pat_ty PatEnv
penv Pat GhcRn
pat TcM r
thing_inside }
HsSplice GhcRn
_ -> String -> TcM (Pat GhcTcId, r)
forall a. String -> a
panic String
"invalid splice in splice pat"
tcPatSig :: Bool
-> HsPatSigType GhcRn
-> ExpSigmaType
-> TcM (TcType,
[(Name,TcTyVar)],
[(Name,TcTyVar)],
HsWrapper)
tcPatSig :: Bool
-> HsPatSigType GhcRn
-> ExpSigmaType
-> TcM (TcType, [(Name, TyVar)], [(Name, TyVar)], HsWrapper)
tcPatSig Bool
in_pat_bind HsPatSigType GhcRn
sig ExpSigmaType
res_ty
= do { ([(Name, TyVar)]
sig_wcs, [(Name, TyVar)]
sig_tvs, TcType
sig_ty) <- UserTypeCtxt
-> HsPatSigType GhcRn
-> TcM ([(Name, TyVar)], [(Name, TyVar)], TcType)
tcHsPatSigType UserTypeCtxt
PatSigCtxt HsPatSigType GhcRn
sig
; if [(Name, TyVar)] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
External instance of the constraint type Foldable []
null [(Name, TyVar)]
sig_tvs then do {
HsWrapper
wrap <- (TidyEnv -> TcM (TidyEnv, SDoc)) -> TcM HsWrapper -> TcM HsWrapper
forall a. (TidyEnv -> TcM (TidyEnv, SDoc)) -> TcM a -> TcM a
addErrCtxtM (TcType -> TidyEnv -> TcM (TidyEnv, SDoc)
mk_msg TcType
sig_ty) (TcM HsWrapper -> TcM HsWrapper) -> TcM HsWrapper -> TcM HsWrapper
forall a b. (a -> b) -> a -> b
$
CtOrigin -> UserTypeCtxt -> ExpSigmaType -> TcType -> TcM HsWrapper
tcSubTypePat CtOrigin
PatSigOrigin UserTypeCtxt
PatSigCtxt ExpSigmaType
res_ty TcType
sig_ty
; (TcType, [(Name, TyVar)], [(Name, TyVar)], HsWrapper)
-> TcM (TcType, [(Name, TyVar)], [(Name, TyVar)], HsWrapper)
forall (m :: * -> *) a. Monad m => a -> m a
External instance of the constraint type forall m. Monad (IOEnv m)
return (TcType
sig_ty, [], [(Name, TyVar)]
sig_wcs, HsWrapper
wrap)
} else do
{ Bool -> TcRn () -> TcRn ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
External instance of the constraint type forall m. Applicative (IOEnv m)
when Bool
in_pat_bind (SDoc -> TcRn ()
addErr ([(Name, TyVar)] -> SDoc
patBindSigErr [(Name, TyVar)]
sig_tvs))
; HsWrapper
wrap <- (TidyEnv -> TcM (TidyEnv, SDoc)) -> TcM HsWrapper -> TcM HsWrapper
forall a. (TidyEnv -> TcM (TidyEnv, SDoc)) -> TcM a -> TcM a
addErrCtxtM (TcType -> TidyEnv -> TcM (TidyEnv, SDoc)
mk_msg TcType
sig_ty) (TcM HsWrapper -> TcM HsWrapper) -> TcM HsWrapper -> TcM HsWrapper
forall a b. (a -> b) -> a -> b
$
CtOrigin -> UserTypeCtxt -> ExpSigmaType -> TcType -> TcM HsWrapper
tcSubTypePat CtOrigin
PatSigOrigin UserTypeCtxt
PatSigCtxt ExpSigmaType
res_ty TcType
sig_ty
; (TcType, [(Name, TyVar)], [(Name, TyVar)], HsWrapper)
-> TcM (TcType, [(Name, TyVar)], [(Name, TyVar)], HsWrapper)
forall (m :: * -> *) a. Monad m => a -> m a
External instance of the constraint type forall m. Monad (IOEnv m)
return (TcType
sig_ty, [(Name, TyVar)]
sig_tvs, [(Name, TyVar)]
sig_wcs, HsWrapper
wrap)
} }
where
mk_msg :: TcType -> TidyEnv -> TcM (TidyEnv, SDoc)
mk_msg TcType
sig_ty TidyEnv
tidy_env
= do { (TidyEnv
tidy_env, TcType
sig_ty) <- TidyEnv -> TcType -> TcM (TidyEnv, TcType)
zonkTidyTcType TidyEnv
tidy_env TcType
sig_ty
; TcType
res_ty <- ExpSigmaType -> TcM TcType
readExpType ExpSigmaType
res_ty
; (TidyEnv
tidy_env, TcType
res_ty) <- TidyEnv -> TcType -> TcM (TidyEnv, TcType)
zonkTidyTcType TidyEnv
tidy_env TcType
res_ty
; let msg :: SDoc
msg = [SDoc] -> SDoc
vcat [ SDoc -> Int -> SDoc -> SDoc
hang (String -> SDoc
text String
"When checking that the pattern signature:")
Int
4 (TcType -> SDoc
forall a. Outputable a => a -> SDoc
External instance of the constraint type Outputable TcType
ppr TcType
sig_ty)
, Int -> SDoc -> SDoc
nest Int
2 (SDoc -> Int -> SDoc -> SDoc
hang (String -> SDoc
text String
"fits the type of its context:")
Int
2 (TcType -> SDoc
forall a. Outputable a => a -> SDoc
External instance of the constraint type Outputable TcType
ppr TcType
res_ty)) ]
; (TidyEnv, SDoc) -> TcM (TidyEnv, SDoc)
forall (m :: * -> *) a. Monad m => a -> m a
External instance of the constraint type forall m. Monad (IOEnv m)
return (TidyEnv
tidy_env, SDoc
msg) }
patBindSigErr :: [(Name,TcTyVar)] -> SDoc
patBindSigErr :: [(Name, TyVar)] -> SDoc
patBindSigErr [(Name, TyVar)]
sig_tvs
= SDoc -> Int -> SDoc -> SDoc
hang (String -> SDoc
text String
"You cannot bind scoped type variable" SDoc -> SDoc -> SDoc
<> [(Name, TyVar)] -> SDoc
forall a. [a] -> SDoc
plural [(Name, TyVar)]
sig_tvs
SDoc -> SDoc -> SDoc
<+> [Name] -> SDoc
forall a. Outputable a => [a] -> SDoc
External instance of the constraint type Outputable Name
pprQuotedList (((Name, TyVar) -> Name) -> [(Name, TyVar)] -> [Name]
forall a b. (a -> b) -> [a] -> [b]
map (Name, TyVar) -> Name
forall a b. (a, b) -> a
fst [(Name, TyVar)]
sig_tvs))
Int
2 (String -> SDoc
text String
"in a pattern binding signature")
tcConPat :: PatEnv -> Located Name
-> ExpSigmaType
-> HsConPatDetails GhcRn -> TcM a
-> TcM (Pat GhcTcId, a)
tcConPat :: PatEnv
-> Located Name
-> ExpSigmaType
-> HsConPatDetails GhcRn
-> TcM a
-> TcM (Pat GhcTcId, a)
tcConPat PatEnv
penv con_lname :: Located Name
con_lname@(L SrcSpan
_ Name
con_name) ExpSigmaType
pat_ty HsConPatDetails GhcRn
arg_pats TcM a
thing_inside
= do { ConLike
con_like <- Name -> TcM ConLike
tcLookupConLike Name
con_name
; case ConLike
con_like of
RealDataCon DataCon
data_con -> PatEnv
-> Located Name
-> DataCon
-> ExpSigmaType
-> HsConPatDetails GhcRn
-> TcM a
-> TcM (Pat GhcTcId, a)
forall a.
PatEnv
-> Located Name
-> DataCon
-> ExpSigmaType
-> HsConPatDetails GhcRn
-> TcM a
-> TcM (Pat GhcTcId, a)
tcDataConPat PatEnv
penv Located Name
con_lname DataCon
data_con
ExpSigmaType
pat_ty HsConPatDetails GhcRn
arg_pats TcM a
thing_inside
PatSynCon PatSyn
pat_syn -> PatEnv
-> Located Name
-> PatSyn
-> ExpSigmaType
-> HsConPatDetails GhcRn
-> TcM a
-> TcM (Pat GhcTcId, a)
forall a.
PatEnv
-> Located Name
-> PatSyn
-> ExpSigmaType
-> HsConPatDetails GhcRn
-> TcM a
-> TcM (Pat GhcTcId, a)
tcPatSynPat PatEnv
penv Located Name
con_lname PatSyn
pat_syn
ExpSigmaType
pat_ty HsConPatDetails GhcRn
arg_pats TcM a
thing_inside
}
tcDataConPat :: PatEnv -> Located Name -> DataCon
-> ExpSigmaType
-> HsConPatDetails GhcRn -> TcM a
-> TcM (Pat GhcTcId, a)
tcDataConPat :: PatEnv
-> Located Name
-> DataCon
-> ExpSigmaType
-> HsConPatDetails GhcRn
-> TcM a
-> TcM (Pat GhcTcId, a)
tcDataConPat PatEnv
penv (L SrcSpan
con_span Name
con_name) DataCon
data_con ExpSigmaType
pat_ty
HsConPatDetails GhcRn
arg_pats TcM a
thing_inside
= do { let tycon :: TyCon
tycon = DataCon -> TyCon
dataConTyCon DataCon
data_con
([TyVar]
univ_tvs, [TyVar]
ex_tvs, [EqSpec]
eq_spec, [TcType]
theta, [TcType]
arg_tys, TcType
_)
= DataCon -> ([TyVar], [TyVar], [EqSpec], [TcType], [TcType], TcType)
dataConFullSig DataCon
data_con
header :: GenLocated SrcSpan ConLike
header = SrcSpan -> ConLike -> GenLocated SrcSpan ConLike
forall l e. l -> e -> GenLocated l e
L SrcSpan
con_span (DataCon -> ConLike
RealDataCon DataCon
data_con)
; (HsWrapper
wrap, [TcType]
ctxt_res_tys) <- PatEnv -> TyCon -> ExpSigmaType -> TcM (HsWrapper, [TcType])
matchExpectedConTy PatEnv
penv TyCon
tycon ExpSigmaType
pat_ty
; TcType
pat_ty <- ExpSigmaType -> TcM TcType
readExpType ExpSigmaType
pat_ty
; SrcSpan -> TcRn () -> TcRn ()
forall a. SrcSpan -> TcRn a -> TcRn a
setSrcSpan SrcSpan
con_span (TcRn () -> TcRn ()) -> TcRn () -> TcRn ()
forall a b. (a -> b) -> a -> b
$ DataCon -> [TcType] -> TcRn ()
addDataConStupidTheta DataCon
data_con [TcType]
ctxt_res_tys
; let all_arg_tys :: [TcType]
all_arg_tys = [EqSpec] -> [TcType]
eqSpecPreds [EqSpec]
eq_spec [TcType] -> [TcType] -> [TcType]
forall a. [a] -> [a] -> [a]
++ [TcType]
theta [TcType] -> [TcType] -> [TcType]
forall a. [a] -> [a] -> [a]
++ [TcType]
arg_tys
; [TyVar] -> [TcType] -> PatEnv -> TcRn ()
checkExistentials [TyVar]
ex_tvs [TcType]
all_arg_tys PatEnv
penv
; TCvSubst
tenv <- CtOrigin -> [TyVar] -> [TcType] -> TcM TCvSubst
instTyVarsWith CtOrigin
PatOrigin [TyVar]
univ_tvs [TcType]
ctxt_res_tys
; (TCvSubst
tenv, [TyVar]
ex_tvs') <- TCvSubst -> [TyVar] -> TcM (TCvSubst, [TyVar])
tcInstSuperSkolTyVarsX TCvSubst
tenv [TyVar]
ex_tvs
; let
arg_tys' :: [TcType]
arg_tys' = HasCallStack => TCvSubst -> [TcType] -> [TcType]
TCvSubst -> [TcType] -> [TcType]
substTys TCvSubst
tenv [TcType]
arg_tys
; String -> SDoc -> TcRn ()
traceTc String
"tcConPat" ([SDoc] -> SDoc
vcat [ Name -> SDoc
forall a. Outputable a => a -> SDoc
External instance of the constraint type Outputable Name
ppr Name
con_name
, [TyVar] -> SDoc
pprTyVars [TyVar]
univ_tvs
, [TyVar] -> SDoc
pprTyVars [TyVar]
ex_tvs
, [EqSpec] -> SDoc
forall a. Outputable a => a -> SDoc
External instance of the constraint type forall a. Outputable a => Outputable [a]
External instance of the constraint type Outputable EqSpec
ppr [EqSpec]
eq_spec
, [TcType] -> SDoc
forall a. Outputable a => a -> SDoc
External instance of the constraint type forall a. Outputable a => Outputable [a]
External instance of the constraint type Outputable TcType
ppr [TcType]
theta
, [TyVar] -> SDoc
pprTyVars [TyVar]
ex_tvs'
, [TcType] -> SDoc
forall a. Outputable a => a -> SDoc
External instance of the constraint type forall a. Outputable a => Outputable [a]
External instance of the constraint type Outputable TcType
ppr [TcType]
ctxt_res_tys
, [TcType] -> SDoc
forall a. Outputable a => a -> SDoc
External instance of the constraint type forall a. Outputable a => Outputable [a]
External instance of the constraint type Outputable TcType
ppr [TcType]
arg_tys'
, HsConDetails
(GenLocated SrcSpan (Pat GhcRn))
(HsRecFields GhcRn (GenLocated SrcSpan (Pat GhcRn)))
-> SDoc
forall a. Outputable a => a -> SDoc
External instance of the constraint type forall arg rec.
(Outputable arg, Outputable rec) =>
Outputable (HsConDetails arg rec)
External instance of the constraint type forall l e.
(Outputable l, Outputable e) =>
Outputable (GenLocated l e)
External instance of the constraint type Outputable SrcSpan
External instance of the constraint type forall (p :: Pass).
OutputableBndrId p =>
Outputable (Pat (GhcPass p))
External instance of the constraint type OutputableBndr Name
External instance of the constraint type OutputableBndr Name
External instance of the constraint type IsPass 'Renamed
External instance of the constraint type forall arg p. Outputable arg => Outputable (HsRecFields p arg)
External instance of the constraint type forall l e.
(Outputable l, Outputable e) =>
Outputable (GenLocated l e)
External instance of the constraint type Outputable SrcSpan
External instance of the constraint type forall (p :: Pass).
OutputableBndrId p =>
Outputable (Pat (GhcPass p))
External instance of the constraint type OutputableBndr Name
External instance of the constraint type OutputableBndr Name
External instance of the constraint type IsPass 'Renamed
ppr HsConDetails
(GenLocated SrcSpan (Pat GhcRn))
(HsRecFields GhcRn (GenLocated SrcSpan (Pat GhcRn)))
HsConPatDetails GhcRn
arg_pats ])
; if [TyVar] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
External instance of the constraint type Foldable []
null [TyVar]
ex_tvs Bool -> Bool -> Bool
&& [EqSpec] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
External instance of the constraint type Foldable []
null [EqSpec]
eq_spec Bool -> Bool -> Bool
&& [TcType] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
External instance of the constraint type Foldable []
null [TcType]
theta
then do {
(HsConDetails
(Located (Pat GhcTcId))
(HsRecFields GhcTcId (Located (Pat GhcTcId)))
arg_pats', a
res) <- ConLike
-> [TcType]
-> Checker (HsConPatDetails GhcRn) (HsConPatDetails GhcTcId)
tcConArgs (DataCon -> ConLike
RealDataCon DataCon
data_con) [TcType]
arg_tys'
PatEnv
penv HsConPatDetails GhcRn
arg_pats TcM a
thing_inside
; let res_pat :: Pat GhcTcId
res_pat = ConPat :: forall p.
XConPat p -> Located (ConLikeP p) -> HsConPatDetails p -> Pat p
ConPat { pat_con :: Located (ConLikeP GhcTcId)
pat_con = GenLocated SrcSpan ConLike
Located (ConLikeP GhcTcId)
header
, pat_args :: HsConPatDetails GhcTcId
pat_args = HsConDetails
(Located (Pat GhcTcId))
(HsRecFields GhcTcId (Located (Pat GhcTcId)))
HsConPatDetails GhcTcId
arg_pats'
, pat_con_ext :: XConPat GhcTcId
pat_con_ext = ConPatTc :: [TcType]
-> [TyVar] -> [TyVar] -> TcEvBinds -> HsWrapper -> ConPatTc
ConPatTc
{ cpt_tvs :: [TyVar]
cpt_tvs = [], cpt_dicts :: [TyVar]
cpt_dicts = []
, cpt_binds :: TcEvBinds
cpt_binds = TcEvBinds
emptyTcEvBinds
, cpt_arg_tys :: [TcType]
cpt_arg_tys = [TcType]
ctxt_res_tys
, cpt_wrap :: HsWrapper
cpt_wrap = HsWrapper
idHsWrapper
}
}
; (Pat GhcTcId, a) -> TcM (Pat GhcTcId, a)
forall (m :: * -> *) a. Monad m => a -> m a
External instance of the constraint type forall m. Monad (IOEnv m)
return (HsWrapper -> Pat GhcTcId -> TcType -> Pat GhcTcId
mkHsWrapPat HsWrapper
wrap Pat GhcTcId
res_pat TcType
pat_ty, a
res) }
else do
{ let theta' :: [TcType]
theta' = HasCallStack => TCvSubst -> [TcType] -> [TcType]
TCvSubst -> [TcType] -> [TcType]
substTheta TCvSubst
tenv ([EqSpec] -> [TcType]
eqSpecPreds [EqSpec]
eq_spec [TcType] -> [TcType] -> [TcType]
forall a. [a] -> [a] -> [a]
++ [TcType]
theta)
no_equalities :: Bool
no_equalities = [EqSpec] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
External instance of the constraint type Foldable []
null [EqSpec]
eq_spec Bool -> Bool -> Bool
&& Bool -> Bool
not ((TcType -> Bool) -> [TcType] -> Bool
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
External instance of the constraint type Foldable []
any TcType -> Bool
isEqPred [TcType]
theta)
skol_info :: SkolemInfo
skol_info = ConLike -> HsMatchContext GhcRn -> SkolemInfo
PatSkol (DataCon -> ConLike
RealDataCon DataCon
data_con) HsMatchContext GhcRn
mc
mc :: HsMatchContext GhcRn
mc = case PatEnv -> PatCtxt
pe_ctxt PatEnv
penv of
LamPat HsMatchContext GhcRn
mc -> HsMatchContext GhcRn
mc
LetPat {} -> HsMatchContext GhcRn
forall p. HsMatchContext p
PatBindRhs
; Bool
gadts_on <- Extension -> IOEnv (Env TcGblEnv TcLclEnv) Bool
forall gbl lcl. Extension -> TcRnIf gbl lcl Bool
xoptM Extension
LangExt.GADTs
; Bool
families_on <- Extension -> IOEnv (Env TcGblEnv TcLclEnv) Bool
forall gbl lcl. Extension -> TcRnIf gbl lcl Bool
xoptM Extension
LangExt.TypeFamilies
; Bool -> SDoc -> TcRn ()
checkTc (Bool
no_equalities Bool -> Bool -> Bool
|| Bool
gadts_on Bool -> Bool -> Bool
|| Bool
families_on)
(String -> SDoc
text String
"A pattern match on a GADT requires the" SDoc -> SDoc -> SDoc
<+>
String -> SDoc
text String
"GADTs or TypeFamilies language extension")
; [TyVar]
given <- [TcType] -> TcM [TyVar]
newEvVars [TcType]
theta'
; (TcEvBinds
ev_binds, (HsConDetails
(Located (Pat GhcTcId))
(HsRecFields GhcTcId (Located (Pat GhcTcId)))
arg_pats', a
res))
<- SkolemInfo
-> [TyVar]
-> [TyVar]
-> IOEnv
(Env TcGblEnv TcLclEnv)
(HsConDetails
(Located (Pat GhcTcId))
(HsRecFields GhcTcId (Located (Pat GhcTcId))),
a)
-> TcM
(TcEvBinds,
(HsConDetails
(Located (Pat GhcTcId))
(HsRecFields GhcTcId (Located (Pat GhcTcId))),
a))
forall result.
SkolemInfo
-> [TyVar] -> [TyVar] -> TcM result -> TcM (TcEvBinds, result)
checkConstraints SkolemInfo
skol_info [TyVar]
ex_tvs' [TyVar]
given (IOEnv
(Env TcGblEnv TcLclEnv)
(HsConDetails
(Located (Pat GhcTcId))
(HsRecFields GhcTcId (Located (Pat GhcTcId))),
a)
-> TcM
(TcEvBinds,
(HsConDetails
(Located (Pat GhcTcId))
(HsRecFields GhcTcId (Located (Pat GhcTcId))),
a)))
-> IOEnv
(Env TcGblEnv TcLclEnv)
(HsConDetails
(Located (Pat GhcTcId))
(HsRecFields GhcTcId (Located (Pat GhcTcId))),
a)
-> TcM
(TcEvBinds,
(HsConDetails
(Located (Pat GhcTcId))
(HsRecFields GhcTcId (Located (Pat GhcTcId))),
a))
forall a b. (a -> b) -> a -> b
$
ConLike
-> [TcType]
-> Checker (HsConPatDetails GhcRn) (HsConPatDetails GhcTcId)
tcConArgs (DataCon -> ConLike
RealDataCon DataCon
data_con) [TcType]
arg_tys' PatEnv
penv HsConPatDetails GhcRn
arg_pats TcM a
thing_inside
; let res_pat :: Pat GhcTcId
res_pat = ConPat :: forall p.
XConPat p -> Located (ConLikeP p) -> HsConPatDetails p -> Pat p
ConPat
{ pat_con :: Located (ConLikeP GhcTcId)
pat_con = GenLocated SrcSpan ConLike
Located (ConLikeP GhcTcId)
header
, pat_args :: HsConPatDetails GhcTcId
pat_args = HsConDetails
(Located (Pat GhcTcId))
(HsRecFields GhcTcId (Located (Pat GhcTcId)))
HsConPatDetails GhcTcId
arg_pats'
, pat_con_ext :: XConPat GhcTcId
pat_con_ext = ConPatTc :: [TcType]
-> [TyVar] -> [TyVar] -> TcEvBinds -> HsWrapper -> ConPatTc
ConPatTc
{ cpt_tvs :: [TyVar]
cpt_tvs = [TyVar]
ex_tvs'
, cpt_dicts :: [TyVar]
cpt_dicts = [TyVar]
given
, cpt_binds :: TcEvBinds
cpt_binds = TcEvBinds
ev_binds
, cpt_arg_tys :: [TcType]
cpt_arg_tys = [TcType]
ctxt_res_tys
, cpt_wrap :: HsWrapper
cpt_wrap = HsWrapper
idHsWrapper
}
}
; (Pat GhcTcId, a) -> TcM (Pat GhcTcId, a)
forall (m :: * -> *) a. Monad m => a -> m a
External instance of the constraint type forall m. Monad (IOEnv m)
return (HsWrapper -> Pat GhcTcId -> TcType -> Pat GhcTcId
mkHsWrapPat HsWrapper
wrap Pat GhcTcId
res_pat TcType
pat_ty, a
res)
} }
tcPatSynPat :: PatEnv -> Located Name -> PatSyn
-> ExpSigmaType
-> HsConPatDetails GhcRn -> TcM a
-> TcM (Pat GhcTcId, a)
tcPatSynPat :: PatEnv
-> Located Name
-> PatSyn
-> ExpSigmaType
-> HsConPatDetails GhcRn
-> TcM a
-> TcM (Pat GhcTcId, a)
tcPatSynPat PatEnv
penv (L SrcSpan
con_span Name
_) PatSyn
pat_syn ExpSigmaType
pat_ty HsConPatDetails GhcRn
arg_pats TcM a
thing_inside
= do { let ([TyVar]
univ_tvs, [TcType]
req_theta, [TyVar]
ex_tvs, [TcType]
prov_theta, [TcType]
arg_tys, TcType
ty) = PatSyn -> ([TyVar], [TcType], [TyVar], [TcType], [TcType], TcType)
patSynSig PatSyn
pat_syn
; (TCvSubst
subst, [TyVar]
univ_tvs') <- [TyVar] -> TcM (TCvSubst, [TyVar])
newMetaTyVars [TyVar]
univ_tvs
; let all_arg_tys :: [TcType]
all_arg_tys = TcType
ty TcType -> [TcType] -> [TcType]
forall a. a -> [a] -> [a]
: [TcType]
prov_theta [TcType] -> [TcType] -> [TcType]
forall a. [a] -> [a] -> [a]
++ [TcType]
arg_tys
; [TyVar] -> [TcType] -> PatEnv -> TcRn ()
checkExistentials [TyVar]
ex_tvs [TcType]
all_arg_tys PatEnv
penv
; (TCvSubst
tenv, [TyVar]
ex_tvs') <- TCvSubst -> [TyVar] -> TcM (TCvSubst, [TyVar])
tcInstSuperSkolTyVarsX TCvSubst
subst [TyVar]
ex_tvs
; let ty' :: TcType
ty' = HasCallStack => TCvSubst -> TcType -> TcType
TCvSubst -> TcType -> TcType
substTy TCvSubst
tenv TcType
ty
arg_tys' :: [TcType]
arg_tys' = HasCallStack => TCvSubst -> [TcType] -> [TcType]
TCvSubst -> [TcType] -> [TcType]
substTys TCvSubst
tenv [TcType]
arg_tys
prov_theta' :: [TcType]
prov_theta' = HasCallStack => TCvSubst -> [TcType] -> [TcType]
TCvSubst -> [TcType] -> [TcType]
substTheta TCvSubst
tenv [TcType]
prov_theta
req_theta' :: [TcType]
req_theta' = HasCallStack => TCvSubst -> [TcType] -> [TcType]
TCvSubst -> [TcType] -> [TcType]
substTheta TCvSubst
tenv [TcType]
req_theta
; HsWrapper
wrap <- PatEnv -> ExpSigmaType -> TcType -> TcM HsWrapper
tc_sub_type PatEnv
penv ExpSigmaType
pat_ty TcType
ty'
; String -> SDoc -> TcRn ()
traceTc String
"tcPatSynPat" (PatSyn -> SDoc
forall a. Outputable a => a -> SDoc
External instance of the constraint type Outputable PatSyn
ppr PatSyn
pat_syn SDoc -> SDoc -> SDoc
$$
ExpSigmaType -> SDoc
forall a. Outputable a => a -> SDoc
External instance of the constraint type Outputable ExpSigmaType
ppr ExpSigmaType
pat_ty SDoc -> SDoc -> SDoc
$$
TcType -> SDoc
forall a. Outputable a => a -> SDoc
External instance of the constraint type Outputable TcType
ppr TcType
ty' SDoc -> SDoc -> SDoc
$$
[TyVar] -> SDoc
forall a. Outputable a => a -> SDoc
External instance of the constraint type forall a. Outputable a => Outputable [a]
External instance of the constraint type Outputable TyVar
ppr [TyVar]
ex_tvs' SDoc -> SDoc -> SDoc
$$
[TcType] -> SDoc
forall a. Outputable a => a -> SDoc
External instance of the constraint type forall a. Outputable a => Outputable [a]
External instance of the constraint type Outputable TcType
ppr [TcType]
prov_theta' SDoc -> SDoc -> SDoc
$$
[TcType] -> SDoc
forall a. Outputable a => a -> SDoc
External instance of the constraint type forall a. Outputable a => Outputable [a]
External instance of the constraint type Outputable TcType
ppr [TcType]
req_theta' SDoc -> SDoc -> SDoc
$$
[TcType] -> SDoc
forall a. Outputable a => a -> SDoc
External instance of the constraint type forall a. Outputable a => Outputable [a]
External instance of the constraint type Outputable TcType
ppr [TcType]
arg_tys')
; [TyVar]
prov_dicts' <- [TcType] -> TcM [TyVar]
newEvVars [TcType]
prov_theta'
; let skol_info :: SkolemInfo
skol_info = case PatEnv -> PatCtxt
pe_ctxt PatEnv
penv of
LamPat HsMatchContext GhcRn
mc -> ConLike -> HsMatchContext GhcRn -> SkolemInfo
PatSkol (PatSyn -> ConLike
PatSynCon PatSyn
pat_syn) HsMatchContext GhcRn
mc
LetPat {} -> SkolemInfo
UnkSkol
; HsWrapper
req_wrap <- CtOrigin -> [TcType] -> [TcType] -> TcM HsWrapper
instCall CtOrigin
PatOrigin ([TyVar] -> [TcType]
mkTyVarTys [TyVar]
univ_tvs') [TcType]
req_theta'
; String -> SDoc -> TcRn ()
traceTc String
"instCall" (HsWrapper -> SDoc
forall a. Outputable a => a -> SDoc
External instance of the constraint type Outputable HsWrapper
ppr HsWrapper
req_wrap)
; String -> SDoc -> TcRn ()
traceTc String
"checkConstraints {" SDoc
Outputable.empty
; (TcEvBinds
ev_binds, (HsConDetails
(Located (Pat GhcTcId))
(HsRecFields GhcTcId (Located (Pat GhcTcId)))
arg_pats', a
res))
<- SkolemInfo
-> [TyVar]
-> [TyVar]
-> TcM
(HsConDetails
(Located (Pat GhcTcId))
(HsRecFields GhcTcId (Located (Pat GhcTcId))),
a)
-> TcM
(TcEvBinds,
(HsConDetails
(Located (Pat GhcTcId))
(HsRecFields GhcTcId (Located (Pat GhcTcId))),
a))
forall result.
SkolemInfo
-> [TyVar] -> [TyVar] -> TcM result -> TcM (TcEvBinds, result)
checkConstraints SkolemInfo
skol_info [TyVar]
ex_tvs' [TyVar]
prov_dicts' (TcM
(HsConDetails
(Located (Pat GhcTcId))
(HsRecFields GhcTcId (Located (Pat GhcTcId))),
a)
-> TcM
(TcEvBinds,
(HsConDetails
(Located (Pat GhcTcId))
(HsRecFields GhcTcId (Located (Pat GhcTcId))),
a)))
-> TcM
(HsConDetails
(Located (Pat GhcTcId))
(HsRecFields GhcTcId (Located (Pat GhcTcId))),
a)
-> TcM
(TcEvBinds,
(HsConDetails
(Located (Pat GhcTcId))
(HsRecFields GhcTcId (Located (Pat GhcTcId))),
a))
forall a b. (a -> b) -> a -> b
$
ConLike
-> [TcType]
-> Checker (HsConPatDetails GhcRn) (HsConPatDetails GhcTcId)
tcConArgs (PatSyn -> ConLike
PatSynCon PatSyn
pat_syn) [TcType]
arg_tys' PatEnv
penv HsConPatDetails GhcRn
arg_pats TcM a
thing_inside
; String -> SDoc -> TcRn ()
traceTc String
"checkConstraints }" (TcEvBinds -> SDoc
forall a. Outputable a => a -> SDoc
External instance of the constraint type Outputable TcEvBinds
ppr TcEvBinds
ev_binds)
; let res_pat :: Pat GhcTcId
res_pat = ConPat :: forall p.
XConPat p -> Located (ConLikeP p) -> HsConPatDetails p -> Pat p
ConPat { pat_con :: Located (ConLikeP GhcTcId)
pat_con = SrcSpan -> ConLike -> GenLocated SrcSpan ConLike
forall l e. l -> e -> GenLocated l e
L SrcSpan
con_span (ConLike -> GenLocated SrcSpan ConLike)
-> ConLike -> GenLocated SrcSpan ConLike
forall a b. (a -> b) -> a -> b
$ PatSyn -> ConLike
PatSynCon PatSyn
pat_syn
, pat_args :: HsConPatDetails GhcTcId
pat_args = HsConDetails
(Located (Pat GhcTcId))
(HsRecFields GhcTcId (Located (Pat GhcTcId)))
HsConPatDetails GhcTcId
arg_pats'
, pat_con_ext :: XConPat GhcTcId
pat_con_ext = ConPatTc :: [TcType]
-> [TyVar] -> [TyVar] -> TcEvBinds -> HsWrapper -> ConPatTc
ConPatTc
{ cpt_tvs :: [TyVar]
cpt_tvs = [TyVar]
ex_tvs'
, cpt_dicts :: [TyVar]
cpt_dicts = [TyVar]
prov_dicts'
, cpt_binds :: TcEvBinds
cpt_binds = TcEvBinds
ev_binds
, cpt_arg_tys :: [TcType]
cpt_arg_tys = [TyVar] -> [TcType]
mkTyVarTys [TyVar]
univ_tvs'
, cpt_wrap :: HsWrapper
cpt_wrap = HsWrapper
req_wrap
}
}
; TcType
pat_ty <- ExpSigmaType -> TcM TcType
readExpType ExpSigmaType
pat_ty
; (Pat GhcTcId, a) -> TcM (Pat GhcTcId, a)
forall (m :: * -> *) a. Monad m => a -> m a
External instance of the constraint type forall m. Monad (IOEnv m)
return (HsWrapper -> Pat GhcTcId -> TcType -> Pat GhcTcId
mkHsWrapPat HsWrapper
wrap Pat GhcTcId
res_pat TcType
pat_ty, a
res) }
matchExpectedPatTy :: (TcRhoType -> TcM (TcCoercionN, a))
-> PatEnv -> ExpSigmaType -> TcM (HsWrapper, a)
matchExpectedPatTy :: (TcType -> TcM (TcCoercion, a))
-> PatEnv -> ExpSigmaType -> TcM (HsWrapper, a)
matchExpectedPatTy TcType -> TcM (TcCoercion, a)
inner_match (PE { pe_orig :: PatEnv -> CtOrigin
pe_orig = CtOrigin
orig }) ExpSigmaType
pat_ty
= do { TcType
pat_ty <- ExpSigmaType -> TcM TcType
expTypeToType ExpSigmaType
pat_ty
; (HsWrapper
wrap, TcType
pat_rho) <- CtOrigin -> TcType -> TcM (HsWrapper, TcType)
topInstantiate CtOrigin
orig TcType
pat_ty
; (TcCoercion
co, a
res) <- TcType -> TcM (TcCoercion, a)
inner_match TcType
pat_rho
; String -> SDoc -> TcRn ()
traceTc String
"matchExpectedPatTy" (TcType -> SDoc
forall a. Outputable a => a -> SDoc
External instance of the constraint type Outputable TcType
ppr TcType
pat_ty SDoc -> SDoc -> SDoc
$$ HsWrapper -> SDoc
forall a. Outputable a => a -> SDoc
External instance of the constraint type Outputable HsWrapper
ppr HsWrapper
wrap)
; (HsWrapper, a) -> TcM (HsWrapper, a)
forall (m :: * -> *) a. Monad m => a -> m a
External instance of the constraint type forall m. Monad (IOEnv m)
return (TcCoercion -> HsWrapper
mkWpCastN (TcCoercion -> TcCoercion
mkTcSymCo TcCoercion
co) HsWrapper -> HsWrapper -> HsWrapper
<.> HsWrapper
wrap, a
res) }
matchExpectedConTy :: PatEnv
-> TyCon
-> ExpSigmaType
-> TcM (HsWrapper, [TcSigmaType])
matchExpectedConTy :: PatEnv -> TyCon -> ExpSigmaType -> TcM (HsWrapper, [TcType])
matchExpectedConTy (PE { pe_orig :: PatEnv -> CtOrigin
pe_orig = CtOrigin
orig }) TyCon
data_tc ExpSigmaType
exp_pat_ty
| Just (TyCon
fam_tc, [TcType]
fam_args, CoAxiom Unbranched
co_tc) <- TyCon -> Maybe (TyCon, [TcType], CoAxiom Unbranched)
tyConFamInstSig_maybe TyCon
data_tc
= do { TcType
pat_ty <- ExpSigmaType -> TcM TcType
expTypeToType ExpSigmaType
exp_pat_ty
; (HsWrapper
wrap, TcType
pat_rho) <- CtOrigin -> TcType -> TcM (HsWrapper, TcType)
topInstantiate CtOrigin
orig TcType
pat_ty
; (TCvSubst
subst, [TyVar]
tvs') <- [TyVar] -> TcM (TCvSubst, [TyVar])
newMetaTyVars (TyCon -> [TyVar]
tyConTyVars TyCon
data_tc)
; String -> SDoc -> TcRn ()
traceTc String
"matchExpectedConTy" ([SDoc] -> SDoc
vcat [TyCon -> SDoc
forall a. Outputable a => a -> SDoc
External instance of the constraint type Outputable TyCon
ppr TyCon
data_tc,
[TyVar] -> SDoc
forall a. Outputable a => a -> SDoc
External instance of the constraint type forall a. Outputable a => Outputable [a]
External instance of the constraint type Outputable TyVar
ppr (TyCon -> [TyVar]
tyConTyVars TyCon
data_tc),
TyCon -> SDoc
forall a. Outputable a => a -> SDoc
External instance of the constraint type Outputable TyCon
ppr TyCon
fam_tc, [TcType] -> SDoc
forall a. Outputable a => a -> SDoc
External instance of the constraint type forall a. Outputable a => Outputable [a]
External instance of the constraint type Outputable TcType
ppr [TcType]
fam_args,
ExpSigmaType -> SDoc
forall a. Outputable a => a -> SDoc
External instance of the constraint type Outputable ExpSigmaType
ppr ExpSigmaType
exp_pat_ty,
TcType -> SDoc
forall a. Outputable a => a -> SDoc
External instance of the constraint type Outputable TcType
ppr TcType
pat_ty,
TcType -> SDoc
forall a. Outputable a => a -> SDoc
External instance of the constraint type Outputable TcType
ppr TcType
pat_rho, HsWrapper -> SDoc
forall a. Outputable a => a -> SDoc
External instance of the constraint type Outputable HsWrapper
ppr HsWrapper
wrap])
; TcCoercion
co1 <- Maybe (HsExpr GhcRn) -> TcType -> TcType -> TcM TcCoercion
unifyType Maybe (HsExpr GhcRn)
forall a. Maybe a
Nothing (TyCon -> [TcType] -> TcType
mkTyConApp TyCon
fam_tc (HasCallStack => TCvSubst -> [TcType] -> [TcType]
TCvSubst -> [TcType] -> [TcType]
substTys TCvSubst
subst [TcType]
fam_args)) TcType
pat_rho
; let tys' :: [TcType]
tys' = [TyVar] -> [TcType]
mkTyVarTys [TyVar]
tvs'
co2 :: TcCoercion
co2 = CoAxiom Unbranched -> [TcType] -> [TcCoercion] -> TcCoercion
mkTcUnbranchedAxInstCo CoAxiom Unbranched
co_tc [TcType]
tys' []
full_co :: TcCoercion
full_co = TcCoercion -> TcCoercion
mkTcSubCo (TcCoercion -> TcCoercion
mkTcSymCo TcCoercion
co1) TcCoercion -> TcCoercion -> TcCoercion
`mkTcTransCo` TcCoercion
co2
; (HsWrapper, [TcType]) -> TcM (HsWrapper, [TcType])
forall (m :: * -> *) a. Monad m => a -> m a
External instance of the constraint type forall m. Monad (IOEnv m)
return ( TcCoercion -> HsWrapper
mkWpCastR TcCoercion
full_co HsWrapper -> HsWrapper -> HsWrapper
<.> HsWrapper
wrap, [TcType]
tys') }
| Bool
otherwise
= do { TcType
pat_ty <- ExpSigmaType -> TcM TcType
expTypeToType ExpSigmaType
exp_pat_ty
; (HsWrapper
wrap, TcType
pat_rho) <- CtOrigin -> TcType -> TcM (HsWrapper, TcType)
topInstantiate CtOrigin
orig TcType
pat_ty
; (TcCoercion
coi, [TcType]
tys) <- TyCon -> TcType -> TcM (TcCoercion, [TcType])
matchExpectedTyConApp TyCon
data_tc TcType
pat_rho
; (HsWrapper, [TcType]) -> TcM (HsWrapper, [TcType])
forall (m :: * -> *) a. Monad m => a -> m a
External instance of the constraint type forall m. Monad (IOEnv m)
return (TcCoercion -> HsWrapper
mkWpCastN (TcCoercion -> TcCoercion
mkTcSymCo TcCoercion
coi) HsWrapper -> HsWrapper -> HsWrapper
<.> HsWrapper
wrap, [TcType]
tys) }
tcConArgs :: ConLike -> [TcSigmaType]
-> Checker (HsConPatDetails GhcRn) (HsConPatDetails GhcTc)
tcConArgs :: ConLike
-> [TcType]
-> Checker (HsConPatDetails GhcRn) (HsConPatDetails GhcTcId)
tcConArgs ConLike
con_like [TcType]
arg_tys PatEnv
penv HsConPatDetails GhcRn
con_args TcM r
thing_inside = case HsConPatDetails GhcRn
con_args of
PrefixCon [LPat GhcRn]
arg_pats -> do
{ Bool -> SDoc -> TcRn ()
checkTc (Int
con_arity Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
External instance of the constraint type Eq Int
== Int
no_of_args)
(SDoc -> ConLike -> Int -> Int -> SDoc
forall a. Outputable a => SDoc -> a -> Int -> Int -> SDoc
External instance of the constraint type Outputable ConLike
arityErr (String -> SDoc
text String
"constructor") ConLike
con_like Int
con_arity Int
no_of_args)
; let pats_w_tys :: [(GenLocated SrcSpan (Pat GhcRn), TcType)]
pats_w_tys = String
-> [GenLocated SrcSpan (Pat GhcRn)]
-> [TcType]
-> [(GenLocated SrcSpan (Pat GhcRn), TcType)]
forall a b. String -> [a] -> [b] -> [(a, b)]
zipEqual String
"tcConArgs" [GenLocated SrcSpan (Pat GhcRn)]
[LPat GhcRn]
arg_pats [TcType]
arg_tys
; ([Located (Pat GhcTcId)]
arg_pats', r
res) <- Checker
(GenLocated SrcSpan (Pat GhcRn), TcType) (Located (Pat GhcTcId))
-> Checker
[(GenLocated SrcSpan (Pat GhcRn), TcType)] [Located (Pat GhcTcId)]
forall inp out. Checker inp out -> Checker [inp] [out]
tcMultiple Checker
(GenLocated SrcSpan (Pat GhcRn), TcType) (Located (Pat GhcTcId))
Checker (LPat GhcRn, TcType) (LPat GhcTcId)
tcConArg PatEnv
penv [(GenLocated SrcSpan (Pat GhcRn), TcType)]
pats_w_tys
TcM r
thing_inside
; (HsConDetails
(Located (Pat GhcTcId))
(HsRecFields GhcTcId (Located (Pat GhcTcId))),
r)
-> IOEnv
(Env TcGblEnv TcLclEnv)
(HsConDetails
(Located (Pat GhcTcId))
(HsRecFields GhcTcId (Located (Pat GhcTcId))),
r)
forall (m :: * -> *) a. Monad m => a -> m a
External instance of the constraint type forall m. Monad (IOEnv m)
return ([Located (Pat GhcTcId)]
-> HsConDetails
(Located (Pat GhcTcId))
(HsRecFields GhcTcId (Located (Pat GhcTcId)))
forall arg rec. [arg] -> HsConDetails arg rec
PrefixCon [Located (Pat GhcTcId)]
arg_pats', r
res) }
where
con_arity :: Int
con_arity = ConLike -> Int
conLikeArity ConLike
con_like
no_of_args :: Int
no_of_args = [GenLocated SrcSpan (Pat GhcRn)] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
External instance of the constraint type Foldable []
length [GenLocated SrcSpan (Pat GhcRn)]
[LPat GhcRn]
arg_pats
InfixCon LPat GhcRn
p1 LPat GhcRn
p2 -> do
{ Bool -> SDoc -> TcRn ()
checkTc (Int
con_arity Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
External instance of the constraint type Eq Int
== Int
2)
(SDoc -> ConLike -> Int -> Int -> SDoc
forall a. Outputable a => SDoc -> a -> Int -> Int -> SDoc
External instance of the constraint type Outputable ConLike
arityErr (String -> SDoc
text String
"constructor") ConLike
con_like Int
con_arity Int
2)
; let [TcType
arg_ty1,TcType
arg_ty2] = [TcType]
arg_tys
; ([Located (Pat GhcTcId)
p1',Located (Pat GhcTcId)
p2'], r
res) <- Checker
(GenLocated SrcSpan (Pat GhcRn), TcType) (Located (Pat GhcTcId))
-> Checker
[(GenLocated SrcSpan (Pat GhcRn), TcType)] [Located (Pat GhcTcId)]
forall inp out. Checker inp out -> Checker [inp] [out]
tcMultiple Checker
(GenLocated SrcSpan (Pat GhcRn), TcType) (Located (Pat GhcTcId))
Checker (LPat GhcRn, TcType) (LPat GhcTcId)
tcConArg PatEnv
penv [(GenLocated SrcSpan (Pat GhcRn)
LPat GhcRn
p1,TcType
arg_ty1),(GenLocated SrcSpan (Pat GhcRn)
LPat GhcRn
p2,TcType
arg_ty2)]
TcM r
thing_inside
; (HsConDetails
(Located (Pat GhcTcId))
(HsRecFields GhcTcId (Located (Pat GhcTcId))),
r)
-> IOEnv
(Env TcGblEnv TcLclEnv)
(HsConDetails
(Located (Pat GhcTcId))
(HsRecFields GhcTcId (Located (Pat GhcTcId))),
r)
forall (m :: * -> *) a. Monad m => a -> m a
External instance of the constraint type forall m. Monad (IOEnv m)
return (Located (Pat GhcTcId)
-> Located (Pat GhcTcId)
-> HsConDetails
(Located (Pat GhcTcId))
(HsRecFields GhcTcId (Located (Pat GhcTcId)))
forall arg rec. arg -> arg -> HsConDetails arg rec
InfixCon Located (Pat GhcTcId)
p1' Located (Pat GhcTcId)
p2', r
res) }
where
con_arity :: Int
con_arity = ConLike -> Int
conLikeArity ConLike
con_like
RecCon (HsRecFields [LHsRecField GhcRn (LPat GhcRn)]
rpats Maybe (Located Int)
dd) -> do
{ ([LHsRecField GhcTcId (Located (Pat GhcTcId))]
rpats', r
res) <- Checker
(LHsRecField GhcRn (GenLocated SrcSpan (Pat GhcRn)))
(LHsRecField GhcTcId (Located (Pat GhcTcId)))
-> Checker
[LHsRecField GhcRn (GenLocated SrcSpan (Pat GhcRn))]
[LHsRecField GhcTcId (Located (Pat GhcTcId))]
forall inp out. Checker inp out -> Checker [inp] [out]
tcMultiple Checker
(LHsRecField GhcRn (GenLocated SrcSpan (Pat GhcRn)))
(LHsRecField GhcTcId (Located (Pat GhcTcId)))
Checker
(LHsRecField GhcRn (LPat GhcRn))
(LHsRecField GhcTcId (LPat GhcTcId))
tc_field PatEnv
penv [LHsRecField GhcRn (GenLocated SrcSpan (Pat GhcRn))]
[LHsRecField GhcRn (LPat GhcRn)]
rpats TcM r
thing_inside
; (HsConDetails
(Located (Pat GhcTcId))
(HsRecFields GhcTcId (Located (Pat GhcTcId))),
r)
-> IOEnv
(Env TcGblEnv TcLclEnv)
(HsConDetails
(Located (Pat GhcTcId))
(HsRecFields GhcTcId (Located (Pat GhcTcId))),
r)
forall (m :: * -> *) a. Monad m => a -> m a
External instance of the constraint type forall m. Monad (IOEnv m)
return (HsRecFields GhcTcId (Located (Pat GhcTcId))
-> HsConDetails
(Located (Pat GhcTcId))
(HsRecFields GhcTcId (Located (Pat GhcTcId)))
forall arg rec. rec -> HsConDetails arg rec
RecCon ([LHsRecField GhcTcId (Located (Pat GhcTcId))]
-> Maybe (Located Int)
-> HsRecFields GhcTcId (Located (Pat GhcTcId))
forall p arg.
[LHsRecField p arg] -> Maybe (Located Int) -> HsRecFields p arg
HsRecFields [LHsRecField GhcTcId (Located (Pat GhcTcId))]
rpats' Maybe (Located Int)
dd), r
res) }
where
tc_field :: Checker (LHsRecField GhcRn (LPat GhcRn))
(LHsRecField GhcTcId (LPat GhcTcId))
tc_field :: PatEnv
-> LHsRecField GhcRn (LPat GhcRn)
-> TcM r
-> TcM (LHsRecField GhcTcId (LPat GhcTcId), r)
tc_field PatEnv
penv
(L SrcSpan
l (HsRecField (L SrcSpan
loc (FieldOcc XCFieldOcc GhcRn
sel (L SrcSpan
lr RdrName
rdr))) LPat GhcRn
pat Bool
pun))
TcM r
thing_inside
= do { TyVar
sel' <- Name -> TcM TyVar
tcLookupId Name
XCFieldOcc GhcRn
sel
; TcType
pat_ty <- SrcSpan -> TcM TcType -> TcM TcType
forall a. SrcSpan -> TcRn a -> TcRn a
setSrcSpan SrcSpan
loc (TcM TcType -> TcM TcType) -> TcM TcType -> TcM TcType
forall a b. (a -> b) -> a -> b
$ Name -> FieldLabelString -> TcM TcType
find_field_ty Name
XCFieldOcc GhcRn
sel
(OccName -> FieldLabelString
occNameFS (OccName -> FieldLabelString) -> OccName -> FieldLabelString
forall a b. (a -> b) -> a -> b
$ RdrName -> OccName
rdrNameOcc RdrName
rdr)
; (Located (Pat GhcTcId)
pat', r
res) <- PatEnv -> (LPat GhcRn, TcType) -> TcM r -> TcM (LPat GhcTcId, r)
Checker (LPat GhcRn, TcType) (LPat GhcTcId)
tcConArg PatEnv
penv (LPat GhcRn
pat, TcType
pat_ty) TcM r
thing_inside
; (LHsRecField GhcTcId (Located (Pat GhcTcId)), r)
-> IOEnv
(Env TcGblEnv TcLclEnv)
(LHsRecField GhcTcId (Located (Pat GhcTcId)), r)
forall (m :: * -> *) a. Monad m => a -> m a
External instance of the constraint type forall m. Monad (IOEnv m)
return (SrcSpan
-> HsRecField' (FieldOcc GhcTcId) (Located (Pat GhcTcId))
-> LHsRecField GhcTcId (Located (Pat GhcTcId))
forall l e. l -> e -> GenLocated l e
L SrcSpan
l (Located (FieldOcc GhcTcId)
-> Located (Pat GhcTcId)
-> Bool
-> HsRecField' (FieldOcc GhcTcId) (Located (Pat GhcTcId))
forall id arg. Located id -> arg -> Bool -> HsRecField' id arg
HsRecField (SrcSpan -> FieldOcc GhcTcId -> Located (FieldOcc GhcTcId)
forall l e. l -> e -> GenLocated l e
L SrcSpan
loc (XCFieldOcc GhcTcId
-> GenLocated SrcSpan RdrName -> FieldOcc GhcTcId
forall pass.
XCFieldOcc pass -> GenLocated SrcSpan RdrName -> FieldOcc pass
FieldOcc TyVar
XCFieldOcc GhcTcId
sel' (SrcSpan -> RdrName -> GenLocated SrcSpan RdrName
forall l e. l -> e -> GenLocated l e
L SrcSpan
lr RdrName
rdr))) Located (Pat GhcTcId)
pat'
Bool
pun), r
res) }
find_field_ty :: Name -> FieldLabelString -> TcM TcType
find_field_ty :: Name -> FieldLabelString -> TcM TcType
find_field_ty Name
sel FieldLabelString
lbl
= case [TcType
ty | (FieldLabel
fl, TcType
ty) <- [(FieldLabel, TcType)]
field_tys, FieldLabel -> Name
forall a. FieldLbl a -> a
flSelector FieldLabel
fl Name -> Name -> Bool
forall a. Eq a => a -> a -> Bool
External instance of the constraint type Eq Name
== Name
sel ] of
[] -> SDoc -> TcM TcType
forall a. SDoc -> TcRn a
failWith (ConLike -> FieldLabelString -> SDoc
badFieldCon ConLike
con_like FieldLabelString
lbl)
(TcType
pat_ty : [TcType]
extras) -> do
String -> SDoc -> TcRn ()
traceTc String
"find_field" (TcType -> SDoc
forall a. Outputable a => a -> SDoc
External instance of the constraint type Outputable TcType
ppr TcType
pat_ty SDoc -> SDoc -> SDoc
<+> [TcType] -> SDoc
forall a. Outputable a => a -> SDoc
External instance of the constraint type forall a. Outputable a => Outputable [a]
External instance of the constraint type Outputable TcType
ppr [TcType]
extras)
ASSERT( null extras ) (return pat_ty)
field_tys :: [(FieldLabel, TcType)]
field_tys :: [(FieldLabel, TcType)]
field_tys = [FieldLabel] -> [TcType] -> [(FieldLabel, TcType)]
forall a b. [a] -> [b] -> [(a, b)]
zip (ConLike -> [FieldLabel]
conLikeFieldLabels ConLike
con_like) [TcType]
arg_tys
tcConArg :: Checker (LPat GhcRn, TcSigmaType) (LPat GhcTc)
tcConArg :: PatEnv -> (LPat GhcRn, TcType) -> TcM r -> TcM (LPat GhcTcId, r)
tcConArg PatEnv
penv (LPat GhcRn
arg_pat, TcType
arg_ty) = ExpSigmaType -> Checker (LPat GhcRn) (LPat GhcTcId)
tc_lpat (TcType -> ExpSigmaType
mkCheckExpType TcType
arg_ty) PatEnv
penv LPat GhcRn
arg_pat
addDataConStupidTheta :: DataCon -> [TcType] -> TcM ()
addDataConStupidTheta :: DataCon -> [TcType] -> TcRn ()
addDataConStupidTheta DataCon
data_con [TcType]
inst_tys
| [TcType] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
External instance of the constraint type Foldable []
null [TcType]
stupid_theta = () -> TcRn ()
forall (m :: * -> *) a. Monad m => a -> m a
External instance of the constraint type forall m. Monad (IOEnv m)
return ()
| Bool
otherwise = CtOrigin -> [TcType] -> TcRn ()
instStupidTheta CtOrigin
origin [TcType]
inst_theta
where
origin :: CtOrigin
origin = Name -> CtOrigin
OccurrenceOf (DataCon -> Name
dataConName DataCon
data_con)
stupid_theta :: [TcType]
stupid_theta = DataCon -> [TcType]
dataConStupidTheta DataCon
data_con
univ_tvs :: [TyVar]
univ_tvs = DataCon -> [TyVar]
dataConUnivTyVars DataCon
data_con
tenv :: TCvSubst
tenv = [TyVar] -> [TcType] -> TCvSubst
HasDebugCallStack => [TyVar] -> [TcType] -> TCvSubst
External instance of the constraint type HasDebugCallStack
zipTvSubst [TyVar]
univ_tvs ([TyVar] -> [TcType] -> [TcType]
forall b a. [b] -> [a] -> [a]
takeList [TyVar]
univ_tvs [TcType]
inst_tys)
inst_theta :: [TcType]
inst_theta = HasCallStack => TCvSubst -> [TcType] -> [TcType]
TCvSubst -> [TcType] -> [TcType]
substTheta TCvSubst
tenv [TcType]
stupid_theta
maybeWrapPatCtxt :: Pat GhcRn -> (TcM a -> TcM b) -> TcM a -> TcM b
maybeWrapPatCtxt :: Pat GhcRn -> (TcM a -> TcM b) -> TcM a -> TcM b
maybeWrapPatCtxt Pat GhcRn
pat TcM a -> TcM b
tcm TcM a
thing_inside
| Bool -> Bool
not (Pat GhcRn -> Bool
forall {p}. Pat p -> Bool
worth_wrapping Pat GhcRn
pat) = TcM a -> TcM b
tcm TcM a
thing_inside
| Bool
otherwise = SDoc -> TcM b -> TcM b
forall a. SDoc -> TcM a -> TcM a
addErrCtxt SDoc
msg (TcM b -> TcM b) -> TcM b -> TcM b
forall a b. (a -> b) -> a -> b
$ TcM a -> TcM b
tcm (TcM a -> TcM b) -> TcM a -> TcM b
forall a b. (a -> b) -> a -> b
$ TcM a -> TcM a
forall a. TcM a -> TcM a
popErrCtxt TcM a
thing_inside
where
worth_wrapping :: Pat p -> Bool
worth_wrapping (VarPat {}) = Bool
False
worth_wrapping (ParPat {}) = Bool
False
worth_wrapping (AsPat {}) = Bool
False
worth_wrapping Pat p
_ = Bool
True
msg :: SDoc
msg = SDoc -> Int -> SDoc -> SDoc
hang (String -> SDoc
text String
"In the pattern:") Int
2 (Pat GhcRn -> SDoc
forall a. Outputable a => a -> SDoc
External instance of the constraint type forall (p :: Pass).
OutputableBndrId p =>
Outputable (Pat (GhcPass p))
External instance of the constraint type OutputableBndr Name
External instance of the constraint type OutputableBndr Name
External instance of the constraint type IsPass 'Renamed
ppr Pat GhcRn
pat)
checkExistentials :: [TyVar]
-> [Type]
-> PatEnv -> TcM ()
checkExistentials :: [TyVar] -> [TcType] -> PatEnv -> TcRn ()
checkExistentials [TyVar]
ex_tvs [TcType]
tys PatEnv
_
| (TyVar -> Bool) -> [TyVar] -> Bool
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
External instance of the constraint type Foldable []
all (Bool -> Bool
not (Bool -> Bool) -> (TyVar -> Bool) -> TyVar -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (TyVar -> VarSet -> Bool
`elemVarSet` [TcType] -> VarSet
tyCoVarsOfTypes [TcType]
tys)) [TyVar]
ex_tvs = () -> TcRn ()
forall (m :: * -> *) a. Monad m => a -> m a
External instance of the constraint type forall m. Monad (IOEnv m)
return ()
checkExistentials [TyVar]
_ [TcType]
_ (PE { pe_ctxt :: PatEnv -> PatCtxt
pe_ctxt = LetPat {}}) = () -> TcRn ()
forall (m :: * -> *) a. Monad m => a -> m a
External instance of the constraint type forall m. Monad (IOEnv m)
return ()
checkExistentials [TyVar]
_ [TcType]
_ (PE { pe_ctxt :: PatEnv -> PatCtxt
pe_ctxt = LamPat HsMatchContext GhcRn
ProcExpr }) = SDoc -> TcRn ()
forall a. SDoc -> TcRn a
failWithTc SDoc
existentialProcPat
checkExistentials [TyVar]
_ [TcType]
_ (PE { pe_lazy :: PatEnv -> Bool
pe_lazy = Bool
True }) = SDoc -> TcRn ()
forall a. SDoc -> TcRn a
failWithTc SDoc
existentialLazyPat
checkExistentials [TyVar]
_ [TcType]
_ PatEnv
_ = () -> TcRn ()
forall (m :: * -> *) a. Monad m => a -> m a
External instance of the constraint type forall m. Monad (IOEnv m)
return ()
existentialLazyPat :: SDoc
existentialLazyPat :: SDoc
existentialLazyPat
= SDoc -> Int -> SDoc -> SDoc
hang (String -> SDoc
text String
"An existential or GADT data constructor cannot be used")
Int
2 (String -> SDoc
text String
"inside a lazy (~) pattern")
existentialProcPat :: SDoc
existentialProcPat :: SDoc
existentialProcPat
= String -> SDoc
text String
"Proc patterns cannot use existential or GADT data constructors"
badFieldCon :: ConLike -> FieldLabelString -> SDoc
badFieldCon :: ConLike -> FieldLabelString -> SDoc
badFieldCon ConLike
con FieldLabelString
field
= [SDoc] -> SDoc
hsep [String -> SDoc
text String
"Constructor" SDoc -> SDoc -> SDoc
<+> SDoc -> SDoc
quotes (ConLike -> SDoc
forall a. Outputable a => a -> SDoc
External instance of the constraint type Outputable ConLike
ppr ConLike
con),
String -> SDoc
text String
"does not have field", SDoc -> SDoc
quotes (FieldLabelString -> SDoc
forall a. Outputable a => a -> SDoc
External instance of the constraint type Outputable FieldLabelString
ppr FieldLabelString
field)]
polyPatSig :: TcType -> SDoc
polyPatSig :: TcType -> SDoc
polyPatSig TcType
sig_ty
= SDoc -> Int -> SDoc -> SDoc
hang (String -> SDoc
text String
"Illegal polymorphic type signature in pattern:")
Int
2 (TcType -> SDoc
forall a. Outputable a => a -> SDoc
External instance of the constraint type Outputable TcType
ppr TcType
sig_ty)