{-# LANGUAGE CPP #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE TupleSections #-}
{-# LANGUAGE TypeFamilies #-}
{-# OPTIONS_GHC -Wno-incomplete-uni-patterns #-}
module GHC.Tc.Gen.Pat
( tcLetPat
, newLetBndr
, LetBndrSpec(..)
, tcCheckPat, tcCheckPat_O, tcInferPat
, tcPats
, addDataConStupidTheta
, badFieldCon
, polyPatSig
)
where
#include "GhclibHsVersions.h"
import GHC.Prelude
import {-# SOURCE #-} GHC.Tc.Gen.Expr( tcSyntaxOp, tcSyntaxOpGen, tcInferRho )
import GHC.Hs
import GHC.Rename.Utils
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.Core.Multiplicity
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.Type
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 GHC.Utils.Panic
import qualified GHC.LanguageExtensions as LangExt
import Control.Arrow ( second )
import Control.Monad
import GHC.Data.List.SetOps ( getNth )
tcLetPat :: (Name -> Maybe TcId)
-> LetBndrSpec
-> LPat GhcRn -> Scaled ExpSigmaType
-> TcM a
-> TcM (LPat GhcTc, a)
tcLetPat :: (Name -> Maybe TcId)
-> LetBndrSpec
-> LPat GhcRn
-> Scaled ExpSigmaType
-> TcM a
-> TcM (LPat GhcTc, a)
tcLetPat Name -> Maybe TcId
sig_fn LetBndrSpec
no_gen LPat GhcRn
pat Scaled ExpSigmaType
pat_ty TcM a
thing_inside
= do { TcLevel
bind_lvl <- TcM TcLevel
getTcLevel
; let ctxt :: PatCtxt
ctxt = LetPat :: TcLevel -> (Name -> Maybe TcId) -> LetBndrSpec -> PatCtxt
LetPat { pc_lvl :: TcLevel
pc_lvl = TcLevel
bind_lvl
, pc_sig_fn :: Name -> Maybe TcId
pc_sig_fn = Name -> Maybe TcId
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 }
; Scaled ExpSigmaType
-> PatEnv -> LPat GhcRn -> TcM a -> TcM (LPat GhcTc, a)
Scaled ExpSigmaType -> Checker (LPat GhcRn) (LPat GhcTc)
tc_lpat Scaled ExpSigmaType
pat_ty PatEnv
penv LPat GhcRn
pat TcM a
thing_inside }
tcPats :: HsMatchContext GhcRn
-> [LPat GhcRn]
-> [Scaled ExpSigmaType]
-> TcM a
-> TcM ([LPat GhcTc], a)
tcPats :: HsMatchContext GhcRn
-> [LPat GhcRn]
-> [Scaled ExpSigmaType]
-> TcM a
-> TcM ([LPat GhcTc], a)
tcPats HsMatchContext GhcRn
ctxt [LPat GhcRn]
pats [Scaled ExpSigmaType]
pat_tys TcM a
thing_inside
= [Scaled ExpSigmaType]
-> PatEnv -> [LPat GhcRn] -> TcM a -> TcM ([LPat GhcTc], a)
[Scaled ExpSigmaType] -> Checker [LPat GhcRn] [LPat GhcTc]
tc_lpats [Scaled 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 GhcTc, a), TcSigmaType)
tcInferPat :: HsMatchContext GhcRn
-> LPat GhcRn -> TcM a -> TcM ((LPat GhcTc, a), TcSigmaType)
tcInferPat HsMatchContext GhcRn
ctxt LPat GhcRn
pat TcM a
thing_inside
= (ExpSigmaType -> TcM (GenLocated SrcSpanAnnA (Pat GhcTc), a))
-> TcM ((GenLocated SrcSpanAnnA (Pat GhcTc), a), TcSigmaType)
forall a. (ExpSigmaType -> TcM a) -> TcM (a, TcSigmaType)
tcInfer ((ExpSigmaType -> TcM (GenLocated SrcSpanAnnA (Pat GhcTc), a))
-> TcM ((GenLocated SrcSpanAnnA (Pat GhcTc), a), TcSigmaType))
-> (ExpSigmaType -> TcM (GenLocated SrcSpanAnnA (Pat GhcTc), a))
-> TcM ((GenLocated SrcSpanAnnA (Pat GhcTc), a), TcSigmaType)
forall a b. (a -> b) -> a -> b
$ \ ExpSigmaType
exp_ty ->
Scaled ExpSigmaType
-> PatEnv -> LPat GhcRn -> TcM a -> TcM (LPat GhcTc, a)
Scaled ExpSigmaType -> Checker (LPat GhcRn) (LPat GhcTc)
tc_lpat (ExpSigmaType -> Scaled ExpSigmaType
forall a. a -> Scaled a
unrestricted 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 -> Scaled TcSigmaType
-> TcM a
-> TcM (LPat GhcTc, a)
tcCheckPat :: HsMatchContext GhcRn
-> LPat GhcRn -> Scaled TcSigmaType -> TcM a -> TcM (LPat GhcTc, a)
tcCheckPat HsMatchContext GhcRn
ctxt = HsMatchContext GhcRn
-> CtOrigin
-> LPat GhcRn
-> Scaled TcSigmaType
-> TcM a
-> TcM (LPat GhcTc, a)
forall a.
HsMatchContext GhcRn
-> CtOrigin
-> LPat GhcRn
-> Scaled TcSigmaType
-> TcM a
-> TcM (LPat GhcTc, a)
tcCheckPat_O HsMatchContext GhcRn
ctxt CtOrigin
PatOrigin
tcCheckPat_O :: HsMatchContext GhcRn
-> CtOrigin
-> LPat GhcRn -> Scaled TcSigmaType
-> TcM a
-> TcM (LPat GhcTc, a)
tcCheckPat_O :: HsMatchContext GhcRn
-> CtOrigin
-> LPat GhcRn
-> Scaled TcSigmaType
-> TcM a
-> TcM (LPat GhcTc, a)
tcCheckPat_O HsMatchContext GhcRn
ctxt CtOrigin
orig LPat GhcRn
pat (Scaled TcSigmaType
pat_mult TcSigmaType
pat_ty) TcM a
thing_inside
= Scaled ExpSigmaType
-> PatEnv -> LPat GhcRn -> TcM a -> TcM (LPat GhcTc, a)
Scaled ExpSigmaType -> Checker (LPat GhcRn) (LPat GhcTc)
tc_lpat (TcSigmaType -> ExpSigmaType -> Scaled ExpSigmaType
forall a. TcSigmaType -> a -> Scaled a
Scaled TcSigmaType
pat_mult (TcSigmaType -> ExpSigmaType
mkCheckExpType TcSigmaType
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 TcId
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 -> Scaled ExpSigmaType -> TcM (HsWrapper, TcId)
tcPatBndr :: PatEnv -> Name -> Scaled ExpSigmaType -> TcM (HsWrapper, TcId)
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 TcId
pc_sig_fn = Name -> Maybe TcId
sig_fn
, pc_new :: PatCtxt -> LetBndrSpec
pc_new = LetBndrSpec
no_gen } })
Name
bndr_name Scaled ExpSigmaType
exp_pat_ty
| Just TcId
bndr_id <- Name -> Maybe TcId
sig_fn Name
bndr_name
= do { HsWrapper
wrap <- PatEnv -> ExpSigmaType -> TcSigmaType -> TcM HsWrapper
tc_sub_type PatEnv
penv (Scaled ExpSigmaType -> ExpSigmaType
forall a. Scaled a -> a
scaledThing Scaled ExpSigmaType
exp_pat_ty) (TcId -> TcSigmaType
idType TcId
bndr_id)
; String -> SDoc -> TcRn ()
traceTc String
"tcPatBndr(sig)" (TcId -> SDoc
forall a. Outputable a => a -> SDoc
ppr TcId
bndr_id SDoc -> SDoc -> SDoc
$$ TcSigmaType -> SDoc
forall a. Outputable a => a -> SDoc
ppr (TcId -> TcSigmaType
idType TcId
bndr_id) SDoc -> SDoc -> SDoc
$$ Scaled ExpSigmaType -> SDoc
forall a. Outputable a => a -> SDoc
ppr Scaled ExpSigmaType
exp_pat_ty)
; (HsWrapper, TcId) -> TcM (HsWrapper, TcId)
forall (m :: * -> *) a. Monad m => a -> m a
return (HsWrapper
wrap, TcId
bndr_id) }
| Bool
otherwise
= do { (TcCoercionN
co, TcSigmaType
bndr_ty) <- case Scaled ExpSigmaType -> ExpSigmaType
forall a. Scaled a -> a
scaledThing Scaled ExpSigmaType
exp_pat_ty of
Check TcSigmaType
pat_ty -> TcLevel
-> TcSigmaType
-> IOEnv (Env TcGblEnv TcLclEnv) (TcCoercionN, TcSigmaType)
promoteTcType TcLevel
bind_lvl TcSigmaType
pat_ty
Infer InferResult
infer_res -> ASSERT( bind_lvl == ir_lvl infer_res )
do { TcSigmaType
bndr_ty <- InferResult -> TcM TcSigmaType
inferResultToType InferResult
infer_res
; (TcCoercionN, TcSigmaType)
-> IOEnv (Env TcGblEnv TcLclEnv) (TcCoercionN, TcSigmaType)
forall (m :: * -> *) a. Monad m => a -> m a
return (TcSigmaType -> TcCoercionN
mkTcNomReflCo TcSigmaType
bndr_ty, TcSigmaType
bndr_ty) }
; let bndr_mult :: TcSigmaType
bndr_mult = Scaled ExpSigmaType -> TcSigmaType
forall a. Scaled a -> TcSigmaType
scaledMult Scaled ExpSigmaType
exp_pat_ty
; TcId
bndr_id <- LetBndrSpec -> Name -> TcSigmaType -> TcSigmaType -> TcM TcId
newLetBndr LetBndrSpec
no_gen Name
bndr_name TcSigmaType
bndr_mult TcSigmaType
bndr_ty
; String -> SDoc -> TcRn ()
traceTc String
"tcPatBndr(nosig)" ([SDoc] -> SDoc
vcat [ TcLevel -> SDoc
forall a. Outputable a => a -> SDoc
ppr TcLevel
bind_lvl
, Scaled ExpSigmaType -> SDoc
forall a. Outputable a => a -> SDoc
ppr Scaled ExpSigmaType
exp_pat_ty, TcSigmaType -> SDoc
forall a. Outputable a => a -> SDoc
ppr TcSigmaType
bndr_ty, TcCoercionN -> SDoc
forall a. Outputable a => a -> SDoc
ppr TcCoercionN
co
, TcId -> SDoc
forall a. Outputable a => a -> SDoc
ppr TcId
bndr_id ])
; (HsWrapper, TcId) -> TcM (HsWrapper, TcId)
forall (m :: * -> *) a. Monad m => a -> m a
return (TcCoercionN -> HsWrapper
mkWpCastN TcCoercionN
co, TcId
bndr_id) }
tcPatBndr PatEnv
_ Name
bndr_name Scaled ExpSigmaType
pat_ty
= do { let pat_mult :: TcSigmaType
pat_mult = Scaled ExpSigmaType -> TcSigmaType
forall a. Scaled a -> TcSigmaType
scaledMult Scaled ExpSigmaType
pat_ty
; TcSigmaType
pat_ty <- ExpSigmaType -> TcM TcSigmaType
expTypeToType (Scaled ExpSigmaType -> ExpSigmaType
forall a. Scaled a -> a
scaledThing Scaled ExpSigmaType
pat_ty)
; String -> SDoc -> TcRn ()
traceTc String
"tcPatBndr(not let)" (Name -> SDoc
forall a. Outputable a => a -> SDoc
ppr Name
bndr_name SDoc -> SDoc -> SDoc
$$ TcSigmaType -> SDoc
forall a. Outputable a => a -> SDoc
ppr TcSigmaType
pat_ty)
; (HsWrapper, TcId) -> TcM (HsWrapper, TcId)
forall (m :: * -> *) a. Monad m => a -> m a
return (HsWrapper
idHsWrapper, Name -> TcSigmaType -> TcSigmaType -> TcId
mkLocalIdOrCoVar Name
bndr_name TcSigmaType
pat_mult TcSigmaType
pat_ty) }
newLetBndr :: LetBndrSpec -> Name -> Mult -> TcType -> TcM TcId
newLetBndr :: LetBndrSpec -> Name -> TcSigmaType -> TcSigmaType -> TcM TcId
newLetBndr LetBndrSpec
LetLclBndr Name
name TcSigmaType
w TcSigmaType
ty
= do { Name
mono_name <- Name -> TcM Name
cloneLocalName Name
name
; TcId -> TcM TcId
forall (m :: * -> *) a. Monad m => a -> m a
return (HasDebugCallStack => Name -> TcSigmaType -> TcSigmaType -> TcId
Name -> TcSigmaType -> TcSigmaType -> TcId
mkLocalId Name
mono_name TcSigmaType
w TcSigmaType
ty) }
newLetBndr (LetGblBndr TcPragEnv
prags) Name
name TcSigmaType
w TcSigmaType
ty
= TcId -> [LSig GhcRn] -> TcM TcId
addInlinePrags (HasDebugCallStack => Name -> TcSigmaType -> TcSigmaType -> TcId
Name -> TcSigmaType -> TcSigmaType -> TcId
mkLocalId Name
name TcSigmaType
w TcSigmaType
ty) (TcPragEnv -> Name -> [LSig GhcRn]
lookupPragEnv TcPragEnv
prags Name
name)
tc_sub_type :: PatEnv -> ExpSigmaType -> TcSigmaType -> TcM HsWrapper
tc_sub_type :: PatEnv -> ExpSigmaType -> TcSigmaType -> TcM HsWrapper
tc_sub_type PatEnv
penv ExpSigmaType
t1 TcSigmaType
t2 = CtOrigin
-> UserTypeCtxt -> ExpSigmaType -> TcSigmaType -> TcM HsWrapper
tcSubTypePat (PatEnv -> CtOrigin
pe_orig PatEnv
penv) UserTypeCtxt
GenSigCtxt ExpSigmaType
t1 TcSigmaType
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
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
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 :: Scaled ExpSigmaType
-> Checker (LPat GhcRn) (LPat GhcTc)
tc_lpat :: Scaled ExpSigmaType -> Checker (LPat GhcRn) (LPat GhcTc)
tc_lpat Scaled ExpSigmaType
pat_ty PatEnv
penv (L span pat) TcM r
thing_inside
= SrcSpanAnnA
-> TcRn (GenLocated SrcSpanAnnA (Pat GhcTc), r)
-> TcRn (GenLocated SrcSpanAnnA (Pat GhcTc), r)
forall ann a. SrcSpanAnn' ann -> TcRn a -> TcRn a
setSrcSpanA SrcSpanAnnA
span (TcRn (GenLocated SrcSpanAnnA (Pat GhcTc), r)
-> TcRn (GenLocated SrcSpanAnnA (Pat GhcTc), r))
-> TcRn (GenLocated SrcSpanAnnA (Pat GhcTc), r)
-> TcRn (GenLocated SrcSpanAnnA (Pat GhcTc), r)
forall a b. (a -> b) -> a -> b
$
do { (Pat GhcTc
pat', r
res) <- Pat GhcRn
-> (TcM r -> TcM (Pat GhcTc, r)) -> TcM r -> TcM (Pat GhcTc, r)
forall a b. Pat GhcRn -> (TcM a -> TcM b) -> TcM a -> TcM b
maybeWrapPatCtxt Pat GhcRn
pat (Scaled ExpSigmaType
-> PatEnv -> Pat GhcRn -> TcM r -> TcM (Pat GhcTc, r)
Scaled ExpSigmaType -> Checker (Pat GhcRn) (Pat GhcTc)
tc_pat Scaled ExpSigmaType
pat_ty PatEnv
penv Pat GhcRn
pat)
TcM r
thing_inside
; (GenLocated SrcSpanAnnA (Pat GhcTc), r)
-> TcRn (GenLocated SrcSpanAnnA (Pat GhcTc), r)
forall (m :: * -> *) a. Monad m => a -> m a
return (SrcSpanAnnA -> Pat GhcTc -> GenLocated SrcSpanAnnA (Pat GhcTc)
forall l e. l -> e -> GenLocated l e
L SrcSpanAnnA
span Pat GhcTc
pat', r
res) }
tc_lpats :: [Scaled ExpSigmaType]
-> Checker [LPat GhcRn] [LPat GhcTc]
tc_lpats :: [Scaled ExpSigmaType] -> Checker [LPat GhcRn] [LPat GhcTc]
tc_lpats [Scaled ExpSigmaType]
tys PatEnv
penv [LPat GhcRn]
pats
= ASSERT2( equalLength pats tys, ppr pats $$ ppr tys )
Checker
(GenLocated SrcSpanAnnA (Pat GhcRn), Scaled ExpSigmaType)
(GenLocated SrcSpanAnnA (Pat GhcTc))
-> PatEnv
-> [(GenLocated SrcSpanAnnA (Pat GhcRn), Scaled ExpSigmaType)]
-> TcRn r
-> TcM ([GenLocated SrcSpanAnnA (Pat GhcTc)], r)
forall inp out. Checker inp out -> Checker [inp] [out]
tcMultiple (\ PatEnv
penv' (p,t) -> Scaled ExpSigmaType
-> PatEnv -> LPat GhcRn -> TcM r -> TcM (LPat GhcTc, r)
Scaled ExpSigmaType -> Checker (LPat GhcRn) (LPat GhcTc)
tc_lpat Scaled ExpSigmaType
t PatEnv
penv' GenLocated SrcSpanAnnA (Pat GhcRn)
LPat GhcRn
p)
PatEnv
penv
(String
-> [GenLocated SrcSpanAnnA (Pat GhcRn)]
-> [Scaled ExpSigmaType]
-> [(GenLocated SrcSpanAnnA (Pat GhcRn), Scaled ExpSigmaType)]
forall a b. String -> [a] -> [b] -> [(a, b)]
zipEqual String
"tc_lpats" [GenLocated SrcSpanAnnA (Pat GhcRn)]
[LPat GhcRn]
pats [Scaled ExpSigmaType]
tys)
checkManyPattern :: Scaled a -> TcM HsWrapper
checkManyPattern :: Scaled a -> TcM HsWrapper
checkManyPattern Scaled a
pat_ty = CtOrigin -> TcSigmaType -> TcSigmaType -> TcM HsWrapper
tcSubMult CtOrigin
NonLinearPatternOrigin TcSigmaType
Many (Scaled a -> TcSigmaType
forall a. Scaled a -> TcSigmaType
scaledMult Scaled a
pat_ty)
tc_pat :: Scaled ExpSigmaType
-> Checker (Pat GhcRn) (Pat GhcTc)
tc_pat :: Scaled ExpSigmaType -> Checker (Pat GhcRn) (Pat GhcTc)
tc_pat Scaled ExpSigmaType
pat_ty PatEnv
penv Pat GhcRn
ps_pat TcM r
thing_inside = case Pat GhcRn
ps_pat of
VarPat XVarPat GhcRn
x (L l name) -> do
{ (HsWrapper
wrap, TcId
id) <- PatEnv -> Name -> Scaled ExpSigmaType -> TcM (HsWrapper, TcId)
tcPatBndr PatEnv
penv Name
name Scaled ExpSigmaType
pat_ty
; (r
res, HsWrapper
mult_wrap) <- Name -> TcSigmaType -> TcM r -> TcM (r, HsWrapper)
forall a. Name -> TcSigmaType -> TcM a -> TcM (a, HsWrapper)
tcCheckUsage Name
name (Scaled ExpSigmaType -> TcSigmaType
forall a. Scaled a -> TcSigmaType
scaledMult Scaled ExpSigmaType
pat_ty) (TcM r -> TcM (r, HsWrapper)) -> TcM r -> TcM (r, HsWrapper)
forall a b. (a -> b) -> a -> b
$
Name -> TcId -> TcM r -> TcM r
forall a. Name -> TcId -> TcM a -> TcM a
tcExtendIdEnv1 Name
name TcId
id TcM r
thing_inside
; TcSigmaType
pat_ty <- ExpSigmaType -> TcM TcSigmaType
readExpType (Scaled ExpSigmaType -> ExpSigmaType
forall a. Scaled a -> a
scaledThing Scaled ExpSigmaType
pat_ty)
; (Pat GhcTc, r) -> TcM (Pat GhcTc, r)
forall (m :: * -> *) a. Monad m => a -> m a
return (HsWrapper -> Pat GhcTc -> TcSigmaType -> Pat GhcTc
mkHsWrapPat (HsWrapper
wrap HsWrapper -> HsWrapper -> HsWrapper
<.> HsWrapper
mult_wrap) (XVarPat GhcTc -> LIdP GhcTc -> Pat GhcTc
forall p. XVarPat p -> LIdP p -> Pat p
VarPat XVarPat GhcRn
XVarPat GhcTc
x (SrcSpanAnnN -> TcId -> GenLocated SrcSpanAnnN TcId
forall l e. l -> e -> GenLocated l e
L SrcSpanAnnN
l TcId
id)) TcSigmaType
pat_ty, r
res) }
ParPat XParPat GhcRn
x LPat GhcRn
pat -> do
{ (GenLocated SrcSpanAnnA (Pat GhcTc)
pat', r
res) <- Scaled ExpSigmaType
-> PatEnv -> LPat GhcRn -> TcM r -> TcM (LPat GhcTc, r)
Scaled ExpSigmaType -> Checker (LPat GhcRn) (LPat GhcTc)
tc_lpat Scaled ExpSigmaType
pat_ty PatEnv
penv LPat GhcRn
pat TcM r
thing_inside
; (Pat GhcTc, r) -> TcM (Pat GhcTc, r)
forall (m :: * -> *) a. Monad m => a -> m a
return (XParPat GhcTc -> LPat GhcTc -> Pat GhcTc
forall p. XParPat p -> LPat p -> Pat p
ParPat XParPat GhcRn
XParPat GhcTc
x GenLocated SrcSpanAnnA (Pat GhcTc)
LPat GhcTc
pat', r
res) }
BangPat XBangPat GhcRn
x LPat GhcRn
pat -> do
{ (GenLocated SrcSpanAnnA (Pat GhcTc)
pat', r
res) <- Scaled ExpSigmaType
-> PatEnv -> LPat GhcRn -> TcM r -> TcM (LPat GhcTc, r)
Scaled ExpSigmaType -> Checker (LPat GhcRn) (LPat GhcTc)
tc_lpat Scaled ExpSigmaType
pat_ty PatEnv
penv LPat GhcRn
pat TcM r
thing_inside
; (Pat GhcTc, r) -> TcM (Pat GhcTc, r)
forall (m :: * -> *) a. Monad m => a -> m a
return (XBangPat GhcTc -> LPat GhcTc -> Pat GhcTc
forall p. XBangPat p -> LPat p -> Pat p
BangPat XBangPat GhcRn
XBangPat GhcTc
x GenLocated SrcSpanAnnA (Pat GhcTc)
LPat GhcTc
pat', r
res) }
LazyPat XLazyPat GhcRn
x LPat GhcRn
pat -> do
{ HsWrapper
mult_wrap <- Scaled ExpSigmaType -> TcM HsWrapper
forall a. Scaled a -> TcM HsWrapper
checkManyPattern Scaled ExpSigmaType
pat_ty
; (GenLocated SrcSpanAnnA (Pat GhcTc)
pat', (r
res, WantedConstraints
pat_ct))
<- Scaled ExpSigmaType
-> PatEnv
-> LPat GhcRn
-> TcM (r, WantedConstraints)
-> TcM (LPat GhcTc, (r, WantedConstraints))
Scaled ExpSigmaType -> Checker (LPat GhcRn) (LPat GhcTc)
tc_lpat Scaled ExpSigmaType
pat_ty (PatEnv -> PatEnv
makeLazy PatEnv
penv) LPat GhcRn
pat (TcM (r, WantedConstraints)
-> TcM (LPat GhcTc, (r, WantedConstraints)))
-> TcM (r, WantedConstraints)
-> TcM (LPat GhcTc, (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
; TcSigmaType
pat_ty <- ExpSigmaType -> TcM TcSigmaType
readExpType (Scaled ExpSigmaType -> ExpSigmaType
forall a. Scaled a -> a
scaledThing Scaled ExpSigmaType
pat_ty)
; TcCoercionN
_ <- Maybe SDoc -> TcSigmaType -> TcSigmaType -> TcM TcCoercionN
unifyType Maybe SDoc
forall a. Maybe a
Nothing (HasDebugCallStack => TcSigmaType -> TcSigmaType
TcSigmaType -> TcSigmaType
tcTypeKind TcSigmaType
pat_ty) TcSigmaType
liftedTypeKind
; (Pat GhcTc, r) -> TcM (Pat GhcTc, r)
forall (m :: * -> *) a. Monad m => a -> m a
return (HsWrapper -> Pat GhcTc -> TcSigmaType -> Pat GhcTc
mkHsWrapPat HsWrapper
mult_wrap (XLazyPat GhcTc -> LPat GhcTc -> Pat GhcTc
forall p. XLazyPat p -> LPat p -> Pat p
LazyPat XLazyPat GhcRn
XLazyPat GhcTc
x GenLocated SrcSpanAnnA (Pat GhcTc)
LPat GhcTc
pat') TcSigmaType
pat_ty, r
res) }
WildPat XWildPat GhcRn
_ -> do
{ HsWrapper
mult_wrap <- Scaled ExpSigmaType -> TcM HsWrapper
forall a. Scaled a -> TcM HsWrapper
checkManyPattern Scaled ExpSigmaType
pat_ty
; r
res <- TcM r
thing_inside
; TcSigmaType
pat_ty <- ExpSigmaType -> TcM TcSigmaType
expTypeToType (Scaled ExpSigmaType -> ExpSigmaType
forall a. Scaled a -> a
scaledThing Scaled ExpSigmaType
pat_ty)
; (Pat GhcTc, r) -> TcM (Pat GhcTc, r)
forall (m :: * -> *) a. Monad m => a -> m a
return (HsWrapper -> Pat GhcTc -> TcSigmaType -> Pat GhcTc
mkHsWrapPat HsWrapper
mult_wrap (XWildPat GhcTc -> Pat GhcTc
forall p. XWildPat p -> Pat p
WildPat TcSigmaType
XWildPat GhcTc
pat_ty) TcSigmaType
pat_ty, r
res) }
AsPat XAsPat GhcRn
x (L nm_loc name) LPat GhcRn
pat -> do
{ HsWrapper
mult_wrap <- Scaled ExpSigmaType -> TcM HsWrapper
forall a. Scaled a -> TcM HsWrapper
checkManyPattern Scaled ExpSigmaType
pat_ty
; (HsWrapper
wrap, TcId
bndr_id) <- SrcSpanAnnN -> TcM (HsWrapper, TcId) -> TcM (HsWrapper, TcId)
forall ann a. SrcSpanAnn' ann -> TcRn a -> TcRn a
setSrcSpanA SrcSpanAnnN
nm_loc (PatEnv -> Name -> Scaled ExpSigmaType -> TcM (HsWrapper, TcId)
tcPatBndr PatEnv
penv Name
name Scaled ExpSigmaType
pat_ty)
; (GenLocated SrcSpanAnnA (Pat GhcTc)
pat', r
res) <- Name
-> TcId
-> IOEnv
(Env TcGblEnv TcLclEnv) (GenLocated SrcSpanAnnA (Pat GhcTc), r)
-> IOEnv
(Env TcGblEnv TcLclEnv) (GenLocated SrcSpanAnnA (Pat GhcTc), r)
forall a. Name -> TcId -> TcM a -> TcM a
tcExtendIdEnv1 Name
name TcId
bndr_id (IOEnv
(Env TcGblEnv TcLclEnv) (GenLocated SrcSpanAnnA (Pat GhcTc), r)
-> IOEnv
(Env TcGblEnv TcLclEnv) (GenLocated SrcSpanAnnA (Pat GhcTc), r))
-> IOEnv
(Env TcGblEnv TcLclEnv) (GenLocated SrcSpanAnnA (Pat GhcTc), r)
-> IOEnv
(Env TcGblEnv TcLclEnv) (GenLocated SrcSpanAnnA (Pat GhcTc), r)
forall a b. (a -> b) -> a -> b
$
Scaled ExpSigmaType
-> PatEnv -> LPat GhcRn -> TcM r -> TcM (LPat GhcTc, r)
Scaled ExpSigmaType -> Checker (LPat GhcRn) (LPat GhcTc)
tc_lpat (Scaled ExpSigmaType
pat_ty Scaled ExpSigmaType -> ExpSigmaType -> Scaled ExpSigmaType
forall a b. Scaled a -> b -> Scaled b
`scaledSet`(TcSigmaType -> ExpSigmaType
mkCheckExpType (TcSigmaType -> ExpSigmaType) -> TcSigmaType -> ExpSigmaType
forall a b. (a -> b) -> a -> b
$ TcId -> TcSigmaType
idType TcId
bndr_id))
PatEnv
penv LPat GhcRn
pat TcM r
thing_inside
; TcSigmaType
pat_ty <- ExpSigmaType -> TcM TcSigmaType
readExpType (Scaled ExpSigmaType -> ExpSigmaType
forall a. Scaled a -> a
scaledThing Scaled ExpSigmaType
pat_ty)
; (Pat GhcTc, r) -> TcM (Pat GhcTc, r)
forall (m :: * -> *) a. Monad m => a -> m a
return (HsWrapper -> Pat GhcTc -> TcSigmaType -> Pat GhcTc
mkHsWrapPat (HsWrapper
wrap HsWrapper -> HsWrapper -> HsWrapper
<.> HsWrapper
mult_wrap) (XAsPat GhcTc -> LIdP GhcTc -> LPat GhcTc -> Pat GhcTc
forall p. XAsPat p -> LIdP p -> LPat p -> Pat p
AsPat XAsPat GhcRn
XAsPat GhcTc
x (SrcSpanAnnN -> TcId -> GenLocated SrcSpanAnnN TcId
forall l e. l -> e -> GenLocated l e
L SrcSpanAnnN
nm_loc TcId
bndr_id) GenLocated SrcSpanAnnA (Pat GhcTc)
LPat GhcTc
pat') TcSigmaType
pat_ty, r
res) }
ViewPat XViewPat GhcRn
_ LHsExpr GhcRn
expr LPat GhcRn
pat -> do
{ HsWrapper
mult_wrap <- Scaled ExpSigmaType -> TcM HsWrapper
forall a. Scaled a -> TcM HsWrapper
checkManyPattern Scaled ExpSigmaType
pat_ty
; (GenLocated SrcSpanAnnA (HsExpr GhcTc)
expr',TcSigmaType
expr_ty) <- LHsExpr GhcRn -> TcM (LHsExpr GhcTc, TcSigmaType)
tcInferRho LHsExpr GhcRn
expr
; let herald :: SDoc
herald = String -> SDoc
text String
"A view pattern expression expects"
; (HsWrapper
expr_wrap1, Scaled TcSigmaType
_mult TcSigmaType
inf_arg_ty, TcSigmaType
inf_res_sigma)
<- SDoc
-> Maybe SDoc
-> (Int, [Scaled TcSigmaType])
-> TcSigmaType
-> TcM (HsWrapper, Scaled TcSigmaType, TcSigmaType)
matchActualFunTySigma SDoc
herald (SDoc -> Maybe SDoc
forall a. a -> Maybe a
Just (GenLocated SrcSpanAnnA (HsExpr GhcRn) -> SDoc
forall a. Outputable a => a -> SDoc
ppr GenLocated SrcSpanAnnA (HsExpr GhcRn)
LHsExpr GhcRn
expr)) (Int
1,[]) TcSigmaType
expr_ty
; HsWrapper
expr_wrap2 <- PatEnv -> ExpSigmaType -> TcSigmaType -> TcM HsWrapper
tc_sub_type PatEnv
penv (Scaled ExpSigmaType -> ExpSigmaType
forall a. Scaled a -> a
scaledThing Scaled ExpSigmaType
pat_ty) TcSigmaType
inf_arg_ty
; (GenLocated SrcSpanAnnA (Pat GhcTc)
pat', r
res) <- Scaled ExpSigmaType
-> PatEnv -> LPat GhcRn -> TcM r -> TcM (LPat GhcTc, r)
Scaled ExpSigmaType -> Checker (LPat GhcRn) (LPat GhcTc)
tc_lpat (Scaled ExpSigmaType
pat_ty Scaled ExpSigmaType -> ExpSigmaType -> Scaled ExpSigmaType
forall a b. Scaled a -> b -> Scaled b
`scaledSet` TcSigmaType -> ExpSigmaType
mkCheckExpType TcSigmaType
inf_res_sigma) PatEnv
penv LPat GhcRn
pat TcM r
thing_inside
; let Scaled TcSigmaType
w ExpSigmaType
h_pat_ty = Scaled ExpSigmaType
pat_ty
; TcSigmaType
pat_ty <- ExpSigmaType -> TcM TcSigmaType
readExpType ExpSigmaType
h_pat_ty
; let expr_wrap2' :: HsWrapper
expr_wrap2' = HsWrapper
-> HsWrapper
-> Scaled TcSigmaType
-> TcSigmaType
-> SDoc
-> HsWrapper
mkWpFun HsWrapper
expr_wrap2 HsWrapper
idHsWrapper
(TcSigmaType -> TcSigmaType -> Scaled TcSigmaType
forall a. TcSigmaType -> a -> Scaled a
Scaled TcSigmaType
w TcSigmaType
pat_ty) TcSigmaType
inf_res_sigma SDoc
doc
expr_wrap :: HsWrapper
expr_wrap = HsWrapper
expr_wrap2' HsWrapper -> HsWrapper -> HsWrapper
<.> HsWrapper
expr_wrap1 HsWrapper -> HsWrapper -> HsWrapper
<.> HsWrapper
mult_wrap
doc :: SDoc
doc = String -> SDoc
text String
"When checking the view pattern function:" SDoc -> SDoc -> SDoc
<+> (GenLocated SrcSpanAnnA (HsExpr GhcRn) -> SDoc
forall a. Outputable a => a -> SDoc
ppr GenLocated SrcSpanAnnA (HsExpr GhcRn)
LHsExpr GhcRn
expr)
; (Pat GhcTc, r) -> TcM (Pat GhcTc, r)
forall (m :: * -> *) a. Monad m => a -> m a
return (XViewPat GhcTc -> LHsExpr GhcTc -> LPat GhcTc -> Pat GhcTc
forall p. XViewPat p -> LHsExpr p -> LPat p -> Pat p
ViewPat TcSigmaType
XViewPat GhcTc
pat_ty (HsWrapper -> LHsExpr GhcTc -> LHsExpr GhcTc
mkLHsWrap HsWrapper
expr_wrap GenLocated SrcSpanAnnA (HsExpr GhcTc)
LHsExpr GhcTc
expr') GenLocated SrcSpanAnnA (Pat GhcTc)
LPat GhcTc
pat', r
res)}
SigPat XSigPat GhcRn
_ LPat GhcRn
pat HsPatSigType (NoGhcTc GhcRn)
sig_ty -> do
{ (TcSigmaType
inner_ty, [(Name, TcId)]
tv_binds, [(Name, TcId)]
wcs, HsWrapper
wrap) <- Bool
-> HsPatSigType GhcRn
-> ExpSigmaType
-> TcM (TcSigmaType, [(Name, TcId)], [(Name, TcId)], HsWrapper)
tcPatSig (PatEnv -> Bool
inPatBind PatEnv
penv)
HsPatSigType GhcRn
HsPatSigType (NoGhcTc GhcRn)
sig_ty (Scaled ExpSigmaType -> ExpSigmaType
forall a. Scaled a -> a
scaledThing Scaled ExpSigmaType
pat_ty)
; (GenLocated SrcSpanAnnA (Pat GhcTc)
pat', r
res) <- [(Name, TcId)]
-> IOEnv
(Env TcGblEnv TcLclEnv) (GenLocated SrcSpanAnnA (Pat GhcTc), r)
-> IOEnv
(Env TcGblEnv TcLclEnv) (GenLocated SrcSpanAnnA (Pat GhcTc), r)
forall r. [(Name, TcId)] -> TcM r -> TcM r
tcExtendNameTyVarEnv [(Name, TcId)]
wcs (IOEnv
(Env TcGblEnv TcLclEnv) (GenLocated SrcSpanAnnA (Pat GhcTc), r)
-> IOEnv
(Env TcGblEnv TcLclEnv) (GenLocated SrcSpanAnnA (Pat GhcTc), r))
-> IOEnv
(Env TcGblEnv TcLclEnv) (GenLocated SrcSpanAnnA (Pat GhcTc), r)
-> IOEnv
(Env TcGblEnv TcLclEnv) (GenLocated SrcSpanAnnA (Pat GhcTc), r)
forall a b. (a -> b) -> a -> b
$
[(Name, TcId)]
-> IOEnv
(Env TcGblEnv TcLclEnv) (GenLocated SrcSpanAnnA (Pat GhcTc), r)
-> IOEnv
(Env TcGblEnv TcLclEnv) (GenLocated SrcSpanAnnA (Pat GhcTc), r)
forall r. [(Name, TcId)] -> TcM r -> TcM r
tcExtendNameTyVarEnv [(Name, TcId)]
tv_binds (IOEnv
(Env TcGblEnv TcLclEnv) (GenLocated SrcSpanAnnA (Pat GhcTc), r)
-> IOEnv
(Env TcGblEnv TcLclEnv) (GenLocated SrcSpanAnnA (Pat GhcTc), r))
-> IOEnv
(Env TcGblEnv TcLclEnv) (GenLocated SrcSpanAnnA (Pat GhcTc), r)
-> IOEnv
(Env TcGblEnv TcLclEnv) (GenLocated SrcSpanAnnA (Pat GhcTc), r)
forall a b. (a -> b) -> a -> b
$
Scaled ExpSigmaType
-> PatEnv -> LPat GhcRn -> TcM r -> TcM (LPat GhcTc, r)
Scaled ExpSigmaType -> Checker (LPat GhcRn) (LPat GhcTc)
tc_lpat (Scaled ExpSigmaType
pat_ty Scaled ExpSigmaType -> ExpSigmaType -> Scaled ExpSigmaType
forall a b. Scaled a -> b -> Scaled b
`scaledSet` TcSigmaType -> ExpSigmaType
mkCheckExpType TcSigmaType
inner_ty) PatEnv
penv LPat GhcRn
pat TcM r
thing_inside
; TcSigmaType
pat_ty <- ExpSigmaType -> TcM TcSigmaType
readExpType (Scaled ExpSigmaType -> ExpSigmaType
forall a. Scaled a -> a
scaledThing Scaled ExpSigmaType
pat_ty)
; (Pat GhcTc, r) -> TcM (Pat GhcTc, r)
forall (m :: * -> *) a. Monad m => a -> m a
return (HsWrapper -> Pat GhcTc -> TcSigmaType -> Pat GhcTc
mkHsWrapPat HsWrapper
wrap (XSigPat GhcTc
-> LPat GhcTc -> HsPatSigType (NoGhcTc GhcTc) -> Pat GhcTc
forall p. XSigPat p -> LPat p -> HsPatSigType (NoGhcTc p) -> Pat p
SigPat TcSigmaType
XSigPat GhcTc
inner_ty GenLocated SrcSpanAnnA (Pat GhcTc)
LPat GhcTc
pat' HsPatSigType (NoGhcTc GhcRn)
HsPatSigType (NoGhcTc GhcTc)
sig_ty) TcSigmaType
pat_ty, r
res) }
ListPat XListPat GhcRn
Nothing [LPat GhcRn]
pats -> do
{ (HsWrapper
coi, TcSigmaType
elt_ty) <- (TcSigmaType
-> IOEnv (Env TcGblEnv TcLclEnv) (TcCoercionN, TcSigmaType))
-> PatEnv -> ExpSigmaType -> TcM (HsWrapper, TcSigmaType)
forall a.
(TcSigmaType -> TcM (TcCoercionN, a))
-> PatEnv -> ExpSigmaType -> TcM (HsWrapper, a)
matchExpectedPatTy TcSigmaType
-> IOEnv (Env TcGblEnv TcLclEnv) (TcCoercionN, TcSigmaType)
matchExpectedListTy PatEnv
penv (Scaled ExpSigmaType -> ExpSigmaType
forall a. Scaled a -> a
scaledThing Scaled ExpSigmaType
pat_ty)
; ([GenLocated SrcSpanAnnA (Pat GhcTc)]
pats', r
res) <- Checker
(GenLocated SrcSpanAnnA (Pat GhcRn))
(GenLocated SrcSpanAnnA (Pat GhcTc))
-> PatEnv
-> [GenLocated SrcSpanAnnA (Pat GhcRn)]
-> TcM r
-> TcM ([GenLocated SrcSpanAnnA (Pat GhcTc)], r)
forall inp out. Checker inp out -> Checker [inp] [out]
tcMultiple (Scaled ExpSigmaType -> Checker (LPat GhcRn) (LPat GhcTc)
tc_lpat (Scaled ExpSigmaType
pat_ty Scaled ExpSigmaType -> ExpSigmaType -> Scaled ExpSigmaType
forall a b. Scaled a -> b -> Scaled b
`scaledSet` TcSigmaType -> ExpSigmaType
mkCheckExpType TcSigmaType
elt_ty))
PatEnv
penv [GenLocated SrcSpanAnnA (Pat GhcRn)]
[LPat GhcRn]
pats TcM r
thing_inside
; TcSigmaType
pat_ty <- ExpSigmaType -> TcM TcSigmaType
readExpType (Scaled ExpSigmaType -> ExpSigmaType
forall a. Scaled a -> a
scaledThing Scaled ExpSigmaType
pat_ty)
; (Pat GhcTc, r) -> TcM (Pat GhcTc, r)
forall (m :: * -> *) a. Monad m => a -> m a
return (HsWrapper -> Pat GhcTc -> TcSigmaType -> Pat GhcTc
mkHsWrapPat HsWrapper
coi
(XListPat GhcTc -> [LPat GhcTc] -> Pat GhcTc
forall p. XListPat p -> [LPat p] -> Pat p
ListPat (TcSigmaType -> Maybe (TcSigmaType, SyntaxExpr GhcTc) -> ListPatTc
ListPatTc TcSigmaType
elt_ty Maybe (TcSigmaType, SyntaxExpr GhcTc)
forall a. Maybe a
Nothing) [GenLocated SrcSpanAnnA (Pat GhcTc)]
[LPat GhcTc]
pats') TcSigmaType
pat_ty, r
res)
}
ListPat (Just e) [LPat GhcRn]
pats -> do
{ TcSigmaType
tau_pat_ty <- ExpSigmaType -> TcM TcSigmaType
expTypeToType (Scaled ExpSigmaType -> ExpSigmaType
forall a. Scaled a -> a
scaledThing Scaled ExpSigmaType
pat_ty)
; (([GenLocated SrcSpanAnnA (Pat GhcTc)]
pats', r
res, TcSigmaType
elt_ty), SyntaxExprTc
e')
<- CtOrigin
-> SyntaxExprRn
-> [SyntaxOpType]
-> SyntaxOpType
-> ([TcSigmaType]
-> [TcSigmaType]
-> TcM ([GenLocated SrcSpanAnnA (Pat GhcTc)], r, TcSigmaType))
-> TcM
(([GenLocated SrcSpanAnnA (Pat GhcTc)], r, TcSigmaType),
SyntaxExprTc)
forall a.
CtOrigin
-> SyntaxExprRn
-> [SyntaxOpType]
-> SyntaxOpType
-> ([TcSigmaType] -> [TcSigmaType] -> TcM a)
-> TcM (a, SyntaxExprTc)
tcSyntaxOpGen CtOrigin
ListOrigin SyntaxExprRn
e [ExpSigmaType -> SyntaxOpType
SynType (TcSigmaType -> ExpSigmaType
mkCheckExpType TcSigmaType
tau_pat_ty)]
SyntaxOpType
SynList (([TcSigmaType]
-> [TcSigmaType]
-> TcM ([GenLocated SrcSpanAnnA (Pat GhcTc)], r, TcSigmaType))
-> TcM
(([GenLocated SrcSpanAnnA (Pat GhcTc)], r, TcSigmaType),
SyntaxExprTc))
-> ([TcSigmaType]
-> [TcSigmaType]
-> TcM ([GenLocated SrcSpanAnnA (Pat GhcTc)], r, TcSigmaType))
-> TcM
(([GenLocated SrcSpanAnnA (Pat GhcTc)], r, TcSigmaType),
SyntaxExprTc)
forall a b. (a -> b) -> a -> b
$
\ [TcSigmaType
elt_ty] [TcSigmaType]
_ ->
do { ([GenLocated SrcSpanAnnA (Pat GhcTc)]
pats', r
res) <- Checker
(GenLocated SrcSpanAnnA (Pat GhcRn))
(GenLocated SrcSpanAnnA (Pat GhcTc))
-> PatEnv
-> [GenLocated SrcSpanAnnA (Pat GhcRn)]
-> TcM r
-> TcM ([GenLocated SrcSpanAnnA (Pat GhcTc)], r)
forall inp out. Checker inp out -> Checker [inp] [out]
tcMultiple (Scaled ExpSigmaType -> Checker (LPat GhcRn) (LPat GhcTc)
tc_lpat (Scaled ExpSigmaType
pat_ty Scaled ExpSigmaType -> ExpSigmaType -> Scaled ExpSigmaType
forall a b. Scaled a -> b -> Scaled b
`scaledSet` TcSigmaType -> ExpSigmaType
mkCheckExpType TcSigmaType
elt_ty))
PatEnv
penv [GenLocated SrcSpanAnnA (Pat GhcRn)]
[LPat GhcRn]
pats TcM r
thing_inside
; ([GenLocated SrcSpanAnnA (Pat GhcTc)], r, TcSigmaType)
-> TcM ([GenLocated SrcSpanAnnA (Pat GhcTc)], r, TcSigmaType)
forall (m :: * -> *) a. Monad m => a -> m a
return ([GenLocated SrcSpanAnnA (Pat GhcTc)]
pats', r
res, TcSigmaType
elt_ty) }
; (Pat GhcTc, r) -> TcM (Pat GhcTc, r)
forall (m :: * -> *) a. Monad m => a -> m a
return (XListPat GhcTc -> [LPat GhcTc] -> Pat GhcTc
forall p. XListPat p -> [LPat p] -> Pat p
ListPat (TcSigmaType -> Maybe (TcSigmaType, SyntaxExpr GhcTc) -> ListPatTc
ListPatTc TcSigmaType
elt_ty ((TcSigmaType, SyntaxExprTc) -> Maybe (TcSigmaType, SyntaxExprTc)
forall a. a -> Maybe a
Just (TcSigmaType
tau_pat_ty,SyntaxExprTc
e'))) [GenLocated SrcSpanAnnA (Pat GhcTc)]
[LPat GhcTc]
pats', r
res)
}
TuplePat XTuplePat GhcRn
_ [LPat GhcRn]
pats Boxity
boxity -> do
{ let arity :: Int
arity = [GenLocated SrcSpanAnnA (Pat GhcRn)] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [GenLocated SrcSpanAnnA (Pat GhcRn)]
[LPat GhcRn]
pats
tc :: TyCon
tc = Boxity -> Int -> TyCon
tupleTyCon Boxity
boxity Int
arity
; Int -> TcRn ()
checkTupSize Int
arity
; (HsWrapper
coi, [TcSigmaType]
arg_tys) <- (TcSigmaType -> TcM (TcCoercionN, [TcSigmaType]))
-> PatEnv -> ExpSigmaType -> TcM (HsWrapper, [TcSigmaType])
forall a.
(TcSigmaType -> TcM (TcCoercionN, a))
-> PatEnv -> ExpSigmaType -> TcM (HsWrapper, a)
matchExpectedPatTy (TyCon -> TcSigmaType -> TcM (TcCoercionN, [TcSigmaType])
matchExpectedTyConApp TyCon
tc)
PatEnv
penv (Scaled ExpSigmaType -> ExpSigmaType
forall a. Scaled a -> a
scaledThing Scaled ExpSigmaType
pat_ty)
; let con_arg_tys :: [TcSigmaType]
con_arg_tys = case Boxity
boxity of Boxity
Unboxed -> Int -> [TcSigmaType] -> [TcSigmaType]
forall a. Int -> [a] -> [a]
drop Int
arity [TcSigmaType]
arg_tys
Boxity
Boxed -> [TcSigmaType]
arg_tys
; ([GenLocated SrcSpanAnnA (Pat GhcTc)]
pats', r
res) <- [Scaled ExpSigmaType]
-> PatEnv -> [LPat GhcRn] -> TcM r -> TcM ([LPat GhcTc], r)
[Scaled ExpSigmaType] -> Checker [LPat GhcRn] [LPat GhcTc]
tc_lpats ((TcSigmaType -> Scaled ExpSigmaType)
-> [TcSigmaType] -> [Scaled ExpSigmaType]
forall a b. (a -> b) -> [a] -> [b]
map (Scaled ExpSigmaType -> ExpSigmaType -> Scaled ExpSigmaType
forall a b. Scaled a -> b -> Scaled b
scaledSet Scaled ExpSigmaType
pat_ty (ExpSigmaType -> Scaled ExpSigmaType)
-> (TcSigmaType -> ExpSigmaType)
-> TcSigmaType
-> Scaled ExpSigmaType
forall b c a. (b -> c) -> (a -> b) -> a -> c
. TcSigmaType -> ExpSigmaType
mkCheckExpType) [TcSigmaType]
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
getDynFlags
; let
unmangled_result :: Pat GhcTc
unmangled_result = XTuplePat GhcTc -> [LPat GhcTc] -> Boxity -> Pat GhcTc
forall p. XTuplePat p -> [LPat p] -> Boxity -> Pat p
TuplePat [TcSigmaType]
XTuplePat GhcTc
con_arg_tys [GenLocated SrcSpanAnnA (Pat GhcTc)]
[LPat GhcTc]
pats' Boxity
boxity
possibly_mangled_result :: Pat GhcTc
possibly_mangled_result
| GeneralFlag -> DynFlags -> Bool
gopt GeneralFlag
Opt_IrrefutableTuples DynFlags
dflags Bool -> Bool -> Bool
&&
Boxity -> Bool
isBoxed Boxity
boxity = XLazyPat GhcTc -> LPat GhcTc -> Pat GhcTc
forall p. XLazyPat p -> LPat p -> Pat p
LazyPat NoExtField
XLazyPat GhcTc
noExtField (Pat GhcTc -> GenLocated SrcSpanAnnA (Pat GhcTc)
forall a an. a -> LocatedAn an a
noLocA Pat GhcTc
unmangled_result)
| Bool
otherwise = Pat GhcTc
unmangled_result
; TcSigmaType
pat_ty <- ExpSigmaType -> TcM TcSigmaType
readExpType (Scaled ExpSigmaType -> ExpSigmaType
forall a. Scaled a -> a
scaledThing Scaled ExpSigmaType
pat_ty)
; ASSERT( con_arg_tys `equalLength` pats )
(Pat GhcTc, r) -> TcM (Pat GhcTc, r)
forall (m :: * -> *) a. Monad m => a -> m a
return (HsWrapper -> Pat GhcTc -> TcSigmaType -> Pat GhcTc
mkHsWrapPat HsWrapper
coi Pat GhcTc
possibly_mangled_result TcSigmaType
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, [TcSigmaType]
arg_tys) <- (TcSigmaType -> TcM (TcCoercionN, [TcSigmaType]))
-> PatEnv -> ExpSigmaType -> TcM (HsWrapper, [TcSigmaType])
forall a.
(TcSigmaType -> TcM (TcCoercionN, a))
-> PatEnv -> ExpSigmaType -> TcM (HsWrapper, a)
matchExpectedPatTy (TyCon -> TcSigmaType -> TcM (TcCoercionN, [TcSigmaType])
matchExpectedTyConApp TyCon
tc)
PatEnv
penv (Scaled ExpSigmaType -> ExpSigmaType
forall a. Scaled a -> a
scaledThing Scaled ExpSigmaType
pat_ty)
;
let con_arg_tys :: [TcSigmaType]
con_arg_tys = Int -> [TcSigmaType] -> [TcSigmaType]
forall a. Int -> [a] -> [a]
drop Int
arity [TcSigmaType]
arg_tys
; (GenLocated SrcSpanAnnA (Pat GhcTc)
pat', r
res) <- Scaled ExpSigmaType
-> PatEnv -> LPat GhcRn -> TcM r -> TcM (LPat GhcTc, r)
Scaled ExpSigmaType -> Checker (LPat GhcRn) (LPat GhcTc)
tc_lpat (Scaled ExpSigmaType
pat_ty Scaled ExpSigmaType -> ExpSigmaType -> Scaled ExpSigmaType
forall a b. Scaled a -> b -> Scaled b
`scaledSet` TcSigmaType -> ExpSigmaType
mkCheckExpType ([TcSigmaType]
con_arg_tys [TcSigmaType] -> Int -> TcSigmaType
forall a. Outputable a => [a] -> Int -> a
`getNth` (Int
alt Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1)))
PatEnv
penv LPat GhcRn
pat TcM r
thing_inside
; TcSigmaType
pat_ty <- ExpSigmaType -> TcM TcSigmaType
readExpType (Scaled ExpSigmaType -> ExpSigmaType
forall a. Scaled a -> a
scaledThing Scaled ExpSigmaType
pat_ty)
; (Pat GhcTc, r) -> TcM (Pat GhcTc, r)
forall (m :: * -> *) a. Monad m => a -> m a
return (HsWrapper -> Pat GhcTc -> TcSigmaType -> Pat GhcTc
mkHsWrapPat HsWrapper
coi (XSumPat GhcTc -> LPat GhcTc -> Int -> Int -> Pat GhcTc
forall p. XSumPat p -> LPat p -> Int -> Int -> Pat p
SumPat [TcSigmaType]
XSumPat GhcTc
con_arg_tys GenLocated SrcSpanAnnA (Pat GhcTc)
LPat GhcTc
pat' Int
alt Int
arity) TcSigmaType
pat_ty
, r
res)
}
ConPat XConPat GhcRn
_ XRec GhcRn (ConLikeP GhcRn)
con HsConPatDetails GhcRn
arg_pats ->
PatEnv
-> LocatedN Name
-> Scaled ExpSigmaType
-> HsConPatDetails GhcRn
-> TcM r
-> TcM (Pat GhcTc, r)
forall a.
PatEnv
-> LocatedN Name
-> Scaled ExpSigmaType
-> HsConPatDetails GhcRn
-> TcM a
-> TcM (Pat GhcTc, a)
tcConPat PatEnv
penv LocatedN Name
XRec GhcRn (ConLikeP GhcRn)
con Scaled ExpSigmaType
pat_ty HsConPatDetails GhcRn
arg_pats TcM r
thing_inside
LitPat XLitPat GhcRn
x HsLit GhcRn
simple_lit -> do
{ let lit_ty :: TcSigmaType
lit_ty = HsLit GhcRn -> TcSigmaType
forall (p :: Pass). HsLit (GhcPass p) -> TcSigmaType
hsLitType HsLit GhcRn
simple_lit
; HsWrapper
wrap <- PatEnv -> ExpSigmaType -> TcSigmaType -> TcM HsWrapper
tc_sub_type PatEnv
penv (Scaled ExpSigmaType -> ExpSigmaType
forall a. Scaled a -> a
scaledThing Scaled ExpSigmaType
pat_ty) TcSigmaType
lit_ty
; r
res <- TcM r
thing_inside
; TcSigmaType
pat_ty <- ExpSigmaType -> TcM TcSigmaType
readExpType (Scaled ExpSigmaType -> ExpSigmaType
forall a. Scaled a -> a
scaledThing Scaled ExpSigmaType
pat_ty)
; (Pat GhcTc, r) -> TcM (Pat GhcTc, r)
forall (m :: * -> *) a. Monad m => a -> m a
return ( HsWrapper -> Pat GhcTc -> TcSigmaType -> Pat GhcTc
mkHsWrapPat HsWrapper
wrap (XLitPat GhcTc -> HsLit GhcTc -> Pat GhcTc
forall p. XLitPat p -> HsLit p -> Pat p
LitPat XLitPat GhcRn
XLitPat GhcTc
x (HsLit GhcRn -> HsLit GhcTc
forall (p1 :: Pass) (p2 :: Pass).
HsLit (GhcPass p1) -> HsLit (GhcPass p2)
convertLit HsLit GhcRn
simple_lit)) TcSigmaType
pat_ty
, r
res) }
NPat XNPat GhcRn
_ (L l over_lit) Maybe (SyntaxExpr GhcRn)
mb_neg SyntaxExpr GhcRn
eq -> do
{ HsWrapper
mult_wrap <- Scaled ExpSigmaType -> TcM HsWrapper
forall a. Scaled a -> TcM HsWrapper
checkManyPattern Scaled ExpSigmaType
pat_ty
; let orig :: CtOrigin
orig = HsOverLit GhcRn -> CtOrigin
LiteralOrigin HsOverLit GhcRn
over_lit
; ((HsOverLit GhcTc
lit', Maybe SyntaxExprTc
mb_neg'), SyntaxExprTc
eq')
<- CtOrigin
-> SyntaxExprRn
-> [SyntaxOpType]
-> ExpSigmaType
-> ([TcSigmaType]
-> [TcSigmaType] -> TcM (HsOverLit GhcTc, Maybe SyntaxExprTc))
-> TcM ((HsOverLit GhcTc, Maybe SyntaxExprTc), SyntaxExprTc)
forall a.
CtOrigin
-> SyntaxExprRn
-> [SyntaxOpType]
-> ExpSigmaType
-> ([TcSigmaType] -> [TcSigmaType] -> TcM a)
-> TcM (a, SyntaxExprTc)
tcSyntaxOp CtOrigin
orig SyntaxExprRn
SyntaxExpr GhcRn
eq [ExpSigmaType -> SyntaxOpType
SynType (Scaled ExpSigmaType -> ExpSigmaType
forall a. Scaled a -> a
scaledThing Scaled ExpSigmaType
pat_ty), SyntaxOpType
SynAny]
(TcSigmaType -> ExpSigmaType
mkCheckExpType TcSigmaType
boolTy) (([TcSigmaType]
-> [TcSigmaType] -> TcM (HsOverLit GhcTc, Maybe SyntaxExprTc))
-> TcM ((HsOverLit GhcTc, Maybe SyntaxExprTc), SyntaxExprTc))
-> ([TcSigmaType]
-> [TcSigmaType] -> TcM (HsOverLit GhcTc, Maybe SyntaxExprTc))
-> TcM ((HsOverLit GhcTc, Maybe SyntaxExprTc), SyntaxExprTc)
forall a b. (a -> b) -> a -> b
$
\ [TcSigmaType
neg_lit_ty] [TcSigmaType]
_ ->
let new_over_lit :: TcSigmaType -> TcM (HsOverLit GhcTc)
new_over_lit TcSigmaType
lit_ty = HsOverLit GhcRn -> ExpSigmaType -> TcM (HsOverLit GhcTc)
newOverloadedLit HsOverLit GhcRn
over_lit
(TcSigmaType -> ExpSigmaType
mkCheckExpType TcSigmaType
lit_ty)
in case Maybe (SyntaxExpr GhcRn)
mb_neg of
Maybe (SyntaxExpr GhcRn)
Nothing -> (, Maybe SyntaxExprTc
forall a. Maybe a
Nothing) (HsOverLit GhcTc -> (HsOverLit GhcTc, Maybe SyntaxExprTc))
-> TcM (HsOverLit GhcTc)
-> TcM (HsOverLit GhcTc, Maybe SyntaxExprTc)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> TcSigmaType -> TcM (HsOverLit GhcTc)
new_over_lit TcSigmaType
neg_lit_ty
Just SyntaxExpr GhcRn
neg ->
(SyntaxExprTc -> Maybe SyntaxExprTc)
-> (HsOverLit GhcTc, SyntaxExprTc)
-> (HsOverLit GhcTc, Maybe SyntaxExprTc)
forall (a :: * -> * -> *) b c d.
Arrow a =>
a b c -> a (d, b) (d, c)
second SyntaxExprTc -> Maybe SyntaxExprTc
forall a. a -> Maybe a
Just ((HsOverLit GhcTc, SyntaxExprTc)
-> (HsOverLit GhcTc, Maybe SyntaxExprTc))
-> IOEnv (Env TcGblEnv TcLclEnv) (HsOverLit GhcTc, SyntaxExprTc)
-> TcM (HsOverLit GhcTc, Maybe SyntaxExprTc)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$>
(CtOrigin
-> SyntaxExprRn
-> [SyntaxOpType]
-> ExpSigmaType
-> ([TcSigmaType] -> [TcSigmaType] -> TcM (HsOverLit GhcTc))
-> IOEnv (Env TcGblEnv TcLclEnv) (HsOverLit GhcTc, SyntaxExprTc)
forall a.
CtOrigin
-> SyntaxExprRn
-> [SyntaxOpType]
-> ExpSigmaType
-> ([TcSigmaType] -> [TcSigmaType] -> TcM a)
-> TcM (a, SyntaxExprTc)
tcSyntaxOp CtOrigin
orig SyntaxExprRn
SyntaxExpr GhcRn
neg [SyntaxOpType
SynRho] (TcSigmaType -> ExpSigmaType
mkCheckExpType TcSigmaType
neg_lit_ty) (([TcSigmaType] -> [TcSigmaType] -> TcM (HsOverLit GhcTc))
-> IOEnv (Env TcGblEnv TcLclEnv) (HsOverLit GhcTc, SyntaxExprTc))
-> ([TcSigmaType] -> [TcSigmaType] -> TcM (HsOverLit GhcTc))
-> IOEnv (Env TcGblEnv TcLclEnv) (HsOverLit GhcTc, SyntaxExprTc)
forall a b. (a -> b) -> a -> b
$
\ [TcSigmaType
lit_ty] [TcSigmaType]
_ -> TcSigmaType -> TcM (HsOverLit GhcTc)
new_over_lit TcSigmaType
lit_ty)
; r
res <- TcM r
thing_inside
; TcSigmaType
pat_ty <- ExpSigmaType -> TcM TcSigmaType
readExpType (Scaled ExpSigmaType -> ExpSigmaType
forall a. Scaled a -> a
scaledThing Scaled ExpSigmaType
pat_ty)
; (Pat GhcTc, r) -> TcM (Pat GhcTc, r)
forall (m :: * -> *) a. Monad m => a -> m a
return (HsWrapper -> Pat GhcTc -> TcSigmaType -> Pat GhcTc
mkHsWrapPat HsWrapper
mult_wrap (XNPat GhcTc
-> XRec GhcTc (HsOverLit GhcTc)
-> Maybe (SyntaxExpr GhcTc)
-> SyntaxExpr GhcTc
-> Pat GhcTc
forall p.
XNPat p
-> XRec p (HsOverLit p)
-> Maybe (SyntaxExpr p)
-> SyntaxExpr p
-> Pat p
NPat TcSigmaType
XNPat GhcTc
pat_ty (SrcSpan -> HsOverLit GhcTc -> GenLocated SrcSpan (HsOverLit GhcTc)
forall l e. l -> e -> GenLocated l e
L SrcSpan
l HsOverLit GhcTc
lit') Maybe SyntaxExprTc
Maybe (SyntaxExpr GhcTc)
mb_neg' SyntaxExprTc
SyntaxExpr GhcTc
eq') TcSigmaType
pat_ty, r
res) }
NPlusKPat XNPlusKPat GhcRn
_ (L nm_loc name)
(L loc lit) HsOverLit GhcRn
_ SyntaxExpr GhcRn
ge SyntaxExpr GhcRn
minus -> do
{ HsWrapper
mult_wrap <- Scaled ExpSigmaType -> TcM HsWrapper
forall a. Scaled a -> TcM HsWrapper
checkManyPattern Scaled ExpSigmaType
pat_ty
; let pat_exp_ty :: ExpSigmaType
pat_exp_ty = Scaled ExpSigmaType -> ExpSigmaType
forall a. Scaled a -> a
scaledThing Scaled ExpSigmaType
pat_ty
orig :: CtOrigin
orig = HsOverLit GhcRn -> CtOrigin
LiteralOrigin HsOverLit GhcRn
lit
; (HsOverLit GhcTc
lit1', SyntaxExprTc
ge')
<- CtOrigin
-> SyntaxExprRn
-> [SyntaxOpType]
-> ExpSigmaType
-> ([TcSigmaType] -> [TcSigmaType] -> TcM (HsOverLit GhcTc))
-> IOEnv (Env TcGblEnv TcLclEnv) (HsOverLit GhcTc, SyntaxExprTc)
forall a.
CtOrigin
-> SyntaxExprRn
-> [SyntaxOpType]
-> ExpSigmaType
-> ([TcSigmaType] -> [TcSigmaType] -> TcM a)
-> TcM (a, SyntaxExprTc)
tcSyntaxOp CtOrigin
orig SyntaxExprRn
SyntaxExpr GhcRn
ge [ExpSigmaType -> SyntaxOpType
SynType ExpSigmaType
pat_exp_ty, SyntaxOpType
SynRho]
(TcSigmaType -> ExpSigmaType
mkCheckExpType TcSigmaType
boolTy) (([TcSigmaType] -> [TcSigmaType] -> TcM (HsOverLit GhcTc))
-> IOEnv (Env TcGblEnv TcLclEnv) (HsOverLit GhcTc, SyntaxExprTc))
-> ([TcSigmaType] -> [TcSigmaType] -> TcM (HsOverLit GhcTc))
-> IOEnv (Env TcGblEnv TcLclEnv) (HsOverLit GhcTc, SyntaxExprTc)
forall a b. (a -> b) -> a -> b
$
\ [TcSigmaType
lit1_ty] [TcSigmaType]
_ ->
HsOverLit GhcRn -> ExpSigmaType -> TcM (HsOverLit GhcTc)
newOverloadedLit HsOverLit GhcRn
lit (TcSigmaType -> ExpSigmaType
mkCheckExpType TcSigmaType
lit1_ty)
; ((HsOverLit GhcTc
lit2', HsWrapper
minus_wrap, TcId
bndr_id), SyntaxExprTc
minus')
<- CtOrigin
-> SyntaxExprRn
-> [SyntaxOpType]
-> SyntaxOpType
-> ([TcSigmaType]
-> [TcSigmaType] -> TcM (HsOverLit GhcTc, HsWrapper, TcId))
-> TcM ((HsOverLit GhcTc, HsWrapper, TcId), SyntaxExprTc)
forall a.
CtOrigin
-> SyntaxExprRn
-> [SyntaxOpType]
-> SyntaxOpType
-> ([TcSigmaType] -> [TcSigmaType] -> TcM a)
-> TcM (a, SyntaxExprTc)
tcSyntaxOpGen CtOrigin
orig SyntaxExprRn
SyntaxExpr GhcRn
minus [ExpSigmaType -> SyntaxOpType
SynType ExpSigmaType
pat_exp_ty, SyntaxOpType
SynRho] SyntaxOpType
SynAny (([TcSigmaType]
-> [TcSigmaType] -> TcM (HsOverLit GhcTc, HsWrapper, TcId))
-> TcM ((HsOverLit GhcTc, HsWrapper, TcId), SyntaxExprTc))
-> ([TcSigmaType]
-> [TcSigmaType] -> TcM (HsOverLit GhcTc, HsWrapper, TcId))
-> TcM ((HsOverLit GhcTc, HsWrapper, TcId), SyntaxExprTc)
forall a b. (a -> b) -> a -> b
$
\ [TcSigmaType
lit2_ty, TcSigmaType
var_ty] [TcSigmaType]
_ ->
do { HsOverLit GhcTc
lit2' <- HsOverLit GhcRn -> ExpSigmaType -> TcM (HsOverLit GhcTc)
newOverloadedLit HsOverLit GhcRn
lit (TcSigmaType -> ExpSigmaType
mkCheckExpType TcSigmaType
lit2_ty)
; (HsWrapper
wrap, TcId
bndr_id) <- SrcSpanAnnN -> TcM (HsWrapper, TcId) -> TcM (HsWrapper, TcId)
forall ann a. SrcSpanAnn' ann -> TcRn a -> TcRn a
setSrcSpanA SrcSpanAnnN
nm_loc (TcM (HsWrapper, TcId) -> TcM (HsWrapper, TcId))
-> TcM (HsWrapper, TcId) -> TcM (HsWrapper, TcId)
forall a b. (a -> b) -> a -> b
$
PatEnv -> Name -> Scaled ExpSigmaType -> TcM (HsWrapper, TcId)
tcPatBndr PatEnv
penv Name
name (ExpSigmaType -> Scaled ExpSigmaType
forall a. a -> Scaled a
unrestricted (ExpSigmaType -> Scaled ExpSigmaType)
-> ExpSigmaType -> Scaled ExpSigmaType
forall a b. (a -> b) -> a -> b
$ TcSigmaType -> ExpSigmaType
mkCheckExpType TcSigmaType
var_ty)
; (HsOverLit GhcTc, HsWrapper, TcId)
-> TcM (HsOverLit GhcTc, HsWrapper, TcId)
forall (m :: * -> *) a. Monad m => a -> m a
return (HsOverLit GhcTc
lit2', HsWrapper
wrap, TcId
bndr_id) }
; TcSigmaType
pat_ty <- ExpSigmaType -> TcM TcSigmaType
readExpType ExpSigmaType
pat_exp_ty
; IOEnv (Env TcGblEnv TcLclEnv) Bool -> TcRn () -> TcRn ()
forall (m :: * -> *). Monad m => m Bool -> m () -> 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 -> [TcSigmaType] -> TcRn ()
instStupidTheta CtOrigin
orig [Class -> [TcSigmaType] -> TcSigmaType
mkClassPred Class
icls [TcSigmaType
pat_ty]] }
; r
res <- Name -> TcId -> TcM r -> TcM r
forall a. Name -> TcId -> TcM a -> TcM a
tcExtendIdEnv1 Name
name TcId
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
ppr SyntaxExprTc
minus')
SyntaxExprTc { syn_expr :: SyntaxExprTc -> HsExpr GhcTc
syn_expr = HsExpr GhcTc
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 GhcTc -> [HsWrapper] -> HsWrapper -> SyntaxExprTc
SyntaxExprTc { syn_expr :: HsExpr GhcTc
syn_expr = HsExpr GhcTc
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 GhcTc
pat' = XNPlusKPat GhcTc
-> LIdP GhcTc
-> XRec GhcTc (HsOverLit GhcTc)
-> HsOverLit GhcTc
-> SyntaxExpr GhcTc
-> SyntaxExpr GhcTc
-> Pat GhcTc
forall p.
XNPlusKPat p
-> LIdP p
-> XRec p (HsOverLit p)
-> HsOverLit p
-> SyntaxExpr p
-> SyntaxExpr p
-> Pat p
NPlusKPat TcSigmaType
XNPlusKPat GhcTc
pat_ty (SrcSpanAnnN -> TcId -> GenLocated SrcSpanAnnN TcId
forall l e. l -> e -> GenLocated l e
L SrcSpanAnnN
nm_loc TcId
bndr_id) (SrcSpan -> HsOverLit GhcTc -> GenLocated SrcSpan (HsOverLit GhcTc)
forall l e. l -> e -> GenLocated l e
L SrcSpan
loc HsOverLit GhcTc
lit1') HsOverLit GhcTc
lit2'
SyntaxExprTc
SyntaxExpr GhcTc
ge' SyntaxExprTc
SyntaxExpr GhcTc
minus''
; (Pat GhcTc, r) -> TcM (Pat GhcTc, r)
forall (m :: * -> *) a. Monad m => a -> m a
return (HsWrapper -> Pat GhcTc -> TcSigmaType -> Pat GhcTc
mkHsWrapPat HsWrapper
mult_wrap Pat GhcTc
pat' TcSigmaType
pat_ty, 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
; Scaled ExpSigmaType
-> PatEnv -> Pat GhcRn -> TcM r -> TcM (Pat GhcTc, r)
Scaled ExpSigmaType -> Checker (Pat GhcRn) (Pat GhcTc)
tc_pat Scaled ExpSigmaType
pat_ty PatEnv
penv Pat GhcRn
pat TcM r
thing_inside }
HsSplice GhcRn
_ -> String -> TcM (Pat GhcTc, 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 (TcSigmaType, [(Name, TcId)], [(Name, TcId)], HsWrapper)
tcPatSig Bool
in_pat_bind HsPatSigType GhcRn
sig ExpSigmaType
res_ty
= do { ([(Name, TcId)]
sig_wcs, [(Name, TcId)]
sig_tvs, TcSigmaType
sig_ty) <- UserTypeCtxt
-> HoleMode
-> HsPatSigType GhcRn
-> ContextKind
-> TcM ([(Name, TcId)], [(Name, TcId)], TcSigmaType)
tcHsPatSigType UserTypeCtxt
PatSigCtxt HoleMode
HM_Sig HsPatSigType GhcRn
sig ContextKind
OpenKind
; if [(Name, TcId)] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [(Name, TcId)]
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 (TcSigmaType -> TidyEnv -> TcM (TidyEnv, SDoc)
mk_msg TcSigmaType
sig_ty) (TcM HsWrapper -> TcM HsWrapper) -> TcM HsWrapper -> TcM HsWrapper
forall a b. (a -> b) -> a -> b
$
CtOrigin
-> UserTypeCtxt -> ExpSigmaType -> TcSigmaType -> TcM HsWrapper
tcSubTypePat CtOrigin
PatSigOrigin UserTypeCtxt
PatSigCtxt ExpSigmaType
res_ty TcSigmaType
sig_ty
; (TcSigmaType, [(Name, TcId)], [(Name, TcId)], HsWrapper)
-> TcM (TcSigmaType, [(Name, TcId)], [(Name, TcId)], HsWrapper)
forall (m :: * -> *) a. Monad m => a -> m a
return (TcSigmaType
sig_ty, [], [(Name, TcId)]
sig_wcs, HsWrapper
wrap)
} else do
{ Bool -> TcRn () -> TcRn ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when Bool
in_pat_bind (SDoc -> TcRn ()
addErr ([(Name, TcId)] -> SDoc
patBindSigErr [(Name, TcId)]
sig_tvs))
; HsWrapper
wrap <- (TidyEnv -> TcM (TidyEnv, SDoc)) -> TcM HsWrapper -> TcM HsWrapper
forall a. (TidyEnv -> TcM (TidyEnv, SDoc)) -> TcM a -> TcM a
addErrCtxtM (TcSigmaType -> TidyEnv -> TcM (TidyEnv, SDoc)
mk_msg TcSigmaType
sig_ty) (TcM HsWrapper -> TcM HsWrapper) -> TcM HsWrapper -> TcM HsWrapper
forall a b. (a -> b) -> a -> b
$
CtOrigin
-> UserTypeCtxt -> ExpSigmaType -> TcSigmaType -> TcM HsWrapper
tcSubTypePat CtOrigin
PatSigOrigin UserTypeCtxt
PatSigCtxt ExpSigmaType
res_ty TcSigmaType
sig_ty
; (TcSigmaType, [(Name, TcId)], [(Name, TcId)], HsWrapper)
-> TcM (TcSigmaType, [(Name, TcId)], [(Name, TcId)], HsWrapper)
forall (m :: * -> *) a. Monad m => a -> m a
return (TcSigmaType
sig_ty, [(Name, TcId)]
sig_tvs, [(Name, TcId)]
sig_wcs, HsWrapper
wrap)
} }
where
mk_msg :: TcSigmaType -> TidyEnv -> TcM (TidyEnv, SDoc)
mk_msg TcSigmaType
sig_ty TidyEnv
tidy_env
= do { (TidyEnv
tidy_env, TcSigmaType
sig_ty) <- TidyEnv -> TcSigmaType -> TcM (TidyEnv, TcSigmaType)
zonkTidyTcType TidyEnv
tidy_env TcSigmaType
sig_ty
; TcSigmaType
res_ty <- ExpSigmaType -> TcM TcSigmaType
readExpType ExpSigmaType
res_ty
; (TidyEnv
tidy_env, TcSigmaType
res_ty) <- TidyEnv -> TcSigmaType -> TcM (TidyEnv, TcSigmaType)
zonkTidyTcType TidyEnv
tidy_env TcSigmaType
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 (TcSigmaType -> SDoc
forall a. Outputable a => a -> SDoc
ppr TcSigmaType
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 (TcSigmaType -> SDoc
forall a. Outputable a => a -> SDoc
ppr TcSigmaType
res_ty)) ]
; (TidyEnv, SDoc) -> TcM (TidyEnv, SDoc)
forall (m :: * -> *) a. Monad m => a -> m a
return (TidyEnv
tidy_env, SDoc
msg) }
patBindSigErr :: [(Name,TcTyVar)] -> SDoc
patBindSigErr :: [(Name, TcId)] -> SDoc
patBindSigErr [(Name, TcId)]
sig_tvs
= SDoc -> Int -> SDoc -> SDoc
hang (String -> SDoc
text String
"You cannot bind scoped type variable" SDoc -> SDoc -> SDoc
<> [(Name, TcId)] -> SDoc
forall a. [a] -> SDoc
plural [(Name, TcId)]
sig_tvs
SDoc -> SDoc -> SDoc
<+> [Name] -> SDoc
forall a. Outputable a => [a] -> SDoc
pprQuotedList (((Name, TcId) -> Name) -> [(Name, TcId)] -> [Name]
forall a b. (a -> b) -> [a] -> [b]
map (Name, TcId) -> Name
forall a b. (a, b) -> a
fst [(Name, TcId)]
sig_tvs))
Int
2 (String -> SDoc
text String
"in a pattern binding signature")
tcConPat :: PatEnv -> LocatedN Name
-> Scaled ExpSigmaType
-> HsConPatDetails GhcRn -> TcM a
-> TcM (Pat GhcTc, a)
tcConPat :: PatEnv
-> LocatedN Name
-> Scaled ExpSigmaType
-> HsConPatDetails GhcRn
-> TcM a
-> TcM (Pat GhcTc, a)
tcConPat PatEnv
penv con_lname :: LocatedN Name
con_lname@(L SrcSpanAnnN
_ Name
con_name) Scaled 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
-> LocatedN Name
-> DataCon
-> Scaled ExpSigmaType
-> HsConPatDetails GhcRn
-> TcM a
-> TcM (Pat GhcTc, a)
forall a.
PatEnv
-> LocatedN Name
-> DataCon
-> Scaled ExpSigmaType
-> HsConPatDetails GhcRn
-> TcM a
-> TcM (Pat GhcTc, a)
tcDataConPat PatEnv
penv LocatedN Name
con_lname DataCon
data_con
Scaled ExpSigmaType
pat_ty HsConPatDetails GhcRn
arg_pats TcM a
thing_inside
PatSynCon PatSyn
pat_syn -> PatEnv
-> LocatedN Name
-> PatSyn
-> Scaled ExpSigmaType
-> HsConPatDetails GhcRn
-> TcM a
-> TcM (Pat GhcTc, a)
forall a.
PatEnv
-> LocatedN Name
-> PatSyn
-> Scaled ExpSigmaType
-> HsConPatDetails GhcRn
-> TcM a
-> TcM (Pat GhcTc, a)
tcPatSynPat PatEnv
penv LocatedN Name
con_lname PatSyn
pat_syn
Scaled ExpSigmaType
pat_ty HsConPatDetails GhcRn
arg_pats TcM a
thing_inside
}
tcDataConPat :: PatEnv -> LocatedN Name -> DataCon
-> Scaled ExpSigmaType
-> HsConPatDetails GhcRn -> TcM a
-> TcM (Pat GhcTc, a)
tcDataConPat :: PatEnv
-> LocatedN Name
-> DataCon
-> Scaled ExpSigmaType
-> HsConPatDetails GhcRn
-> TcM a
-> TcM (Pat GhcTc, a)
tcDataConPat PatEnv
penv (L SrcSpanAnnN
con_span Name
con_name) DataCon
data_con Scaled ExpSigmaType
pat_ty_scaled
HsConPatDetails GhcRn
arg_pats TcM a
thing_inside
= do { let tycon :: TyCon
tycon = DataCon -> TyCon
dataConTyCon DataCon
data_con
([TcId]
univ_tvs, [TcId]
ex_tvs, [EqSpec]
eq_spec, [TcSigmaType]
theta, [Scaled TcSigmaType]
arg_tys, TcSigmaType
_)
= DataCon
-> ([TcId], [TcId], [EqSpec], [TcSigmaType], [Scaled TcSigmaType],
TcSigmaType)
dataConFullSig DataCon
data_con
header :: GenLocated SrcSpanAnnN ConLike
header = SrcSpanAnnN -> ConLike -> GenLocated SrcSpanAnnN ConLike
forall l e. l -> e -> GenLocated l e
L SrcSpanAnnN
con_span (DataCon -> ConLike
RealDataCon DataCon
data_con)
; (HsWrapper
wrap, [TcSigmaType]
ctxt_res_tys) <- PatEnv
-> TyCon -> Scaled ExpSigmaType -> TcM (HsWrapper, [TcSigmaType])
matchExpectedConTy PatEnv
penv TyCon
tycon Scaled ExpSigmaType
pat_ty_scaled
; TcSigmaType
pat_ty <- ExpSigmaType -> TcM TcSigmaType
readExpType (Scaled ExpSigmaType -> ExpSigmaType
forall a. Scaled a -> a
scaledThing Scaled ExpSigmaType
pat_ty_scaled)
; SrcSpanAnnN -> TcRn () -> TcRn ()
forall ann a. SrcSpanAnn' ann -> TcRn a -> TcRn a
setSrcSpanA SrcSpanAnnN
con_span (TcRn () -> TcRn ()) -> TcRn () -> TcRn ()
forall a b. (a -> b) -> a -> b
$ DataCon -> [TcSigmaType] -> TcRn ()
addDataConStupidTheta DataCon
data_con [TcSigmaType]
ctxt_res_tys
; let all_arg_tys :: [TcSigmaType]
all_arg_tys = [EqSpec] -> [TcSigmaType]
eqSpecPreds [EqSpec]
eq_spec [TcSigmaType] -> [TcSigmaType] -> [TcSigmaType]
forall a. [a] -> [a] -> [a]
++ [TcSigmaType]
theta [TcSigmaType] -> [TcSigmaType] -> [TcSigmaType]
forall a. [a] -> [a] -> [a]
++ ((Scaled TcSigmaType -> TcSigmaType)
-> [Scaled TcSigmaType] -> [TcSigmaType]
forall a b. (a -> b) -> [a] -> [b]
map Scaled TcSigmaType -> TcSigmaType
forall a. Scaled a -> a
scaledThing [Scaled TcSigmaType]
arg_tys)
; [TcId] -> [TcSigmaType] -> PatEnv -> TcRn ()
checkExistentials [TcId]
ex_tvs [TcSigmaType]
all_arg_tys PatEnv
penv
; TCvSubst
tenv1 <- CtOrigin -> [TcId] -> [TcSigmaType] -> TcM TCvSubst
instTyVarsWith CtOrigin
PatOrigin [TcId]
univ_tvs [TcSigmaType]
ctxt_res_tys
; (TCvSubst
tenv, [TcId]
ex_tvs') <- TCvSubst -> [TcId] -> TcM (TCvSubst, [TcId])
tcInstSuperSkolTyVarsX TCvSubst
tenv1 [TcId]
ex_tvs
; let arg_tys' :: [Scaled TcSigmaType]
arg_tys' = HasCallStack =>
TCvSubst -> [Scaled TcSigmaType] -> [Scaled TcSigmaType]
TCvSubst -> [Scaled TcSigmaType] -> [Scaled TcSigmaType]
substScaledTys TCvSubst
tenv [Scaled TcSigmaType]
arg_tys
pat_mult :: TcSigmaType
pat_mult = Scaled ExpSigmaType -> TcSigmaType
forall a. Scaled a -> TcSigmaType
scaledMult Scaled ExpSigmaType
pat_ty_scaled
arg_tys_scaled :: [Scaled TcSigmaType]
arg_tys_scaled = (Scaled TcSigmaType -> Scaled TcSigmaType)
-> [Scaled TcSigmaType] -> [Scaled TcSigmaType]
forall a b. (a -> b) -> [a] -> [b]
map (TcSigmaType -> Scaled TcSigmaType -> Scaled TcSigmaType
forall a. TcSigmaType -> Scaled a -> Scaled a
scaleScaled TcSigmaType
pat_mult) [Scaled TcSigmaType]
arg_tys'
; String -> SDoc -> TcRn ()
traceTc String
"tcConPat" ([SDoc] -> SDoc
vcat [ Name -> SDoc
forall a. Outputable a => a -> SDoc
ppr Name
con_name
, [TcId] -> SDoc
pprTyVars [TcId]
univ_tvs
, [TcId] -> SDoc
pprTyVars [TcId]
ex_tvs
, [EqSpec] -> SDoc
forall a. Outputable a => a -> SDoc
ppr [EqSpec]
eq_spec
, [TcSigmaType] -> SDoc
forall a. Outputable a => a -> SDoc
ppr [TcSigmaType]
theta
, [TcId] -> SDoc
pprTyVars [TcId]
ex_tvs'
, [TcSigmaType] -> SDoc
forall a. Outputable a => a -> SDoc
ppr [TcSigmaType]
ctxt_res_tys
, [Scaled TcSigmaType] -> SDoc
forall a. Outputable a => a -> SDoc
ppr [Scaled TcSigmaType]
arg_tys'
, HsConDetails
(HsPatSigType GhcRn)
(GenLocated SrcSpanAnnA (Pat GhcRn))
(HsRecFields GhcRn (GenLocated SrcSpanAnnA (Pat GhcRn)))
-> SDoc
forall a. Outputable a => a -> SDoc
ppr HsConDetails
(HsPatSigType GhcRn)
(GenLocated SrcSpanAnnA (Pat GhcRn))
(HsRecFields GhcRn (GenLocated SrcSpanAnnA (Pat GhcRn)))
HsConPatDetails GhcRn
arg_pats ])
; if [TcId] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [TcId]
ex_tvs Bool -> Bool -> Bool
&& [EqSpec] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [EqSpec]
eq_spec Bool -> Bool -> Bool
&& [TcSigmaType] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [TcSigmaType]
theta
then do {
(HsConDetails
(HsPatSigType GhcRn)
(GenLocated SrcSpanAnnA (Pat GhcTc))
(HsRecFields GhcTc (GenLocated SrcSpanAnnA (Pat GhcTc)))
arg_pats', a
res) <- ConLike
-> [Scaled TcSigmaType]
-> TCvSubst
-> PatEnv
-> HsConPatDetails GhcRn
-> TcM a
-> TcM (HsConPatDetails GhcTc, a)
ConLike
-> [Scaled TcSigmaType]
-> TCvSubst
-> Checker (HsConPatDetails GhcRn) (HsConPatDetails GhcTc)
tcConArgs (DataCon -> ConLike
RealDataCon DataCon
data_con) [Scaled TcSigmaType]
arg_tys_scaled
TCvSubst
tenv PatEnv
penv HsConPatDetails GhcRn
arg_pats TcM a
thing_inside
; let res_pat :: Pat GhcTc
res_pat = ConPat :: forall p.
XConPat p -> XRec p (ConLikeP p) -> HsConPatDetails p -> Pat p
ConPat { pat_con :: XRec GhcTc (ConLikeP GhcTc)
pat_con = GenLocated SrcSpanAnnN ConLike
XRec GhcTc (ConLikeP GhcTc)
header
, pat_args :: HsConPatDetails GhcTc
pat_args = HsConDetails
(HsPatSigType GhcRn)
(GenLocated SrcSpanAnnA (Pat GhcTc))
(HsRecFields GhcTc (GenLocated SrcSpanAnnA (Pat GhcTc)))
HsConPatDetails GhcTc
arg_pats'
, pat_con_ext :: XConPat GhcTc
pat_con_ext = ConPatTc :: [TcSigmaType]
-> [TcId] -> [TcId] -> TcEvBinds -> HsWrapper -> ConPatTc
ConPatTc
{ cpt_tvs :: [TcId]
cpt_tvs = [], cpt_dicts :: [TcId]
cpt_dicts = []
, cpt_binds :: TcEvBinds
cpt_binds = TcEvBinds
emptyTcEvBinds
, cpt_arg_tys :: [TcSigmaType]
cpt_arg_tys = [TcSigmaType]
ctxt_res_tys
, cpt_wrap :: HsWrapper
cpt_wrap = HsWrapper
idHsWrapper
}
}
; (Pat GhcTc, a) -> TcM (Pat GhcTc, a)
forall (m :: * -> *) a. Monad m => a -> m a
return (HsWrapper -> Pat GhcTc -> TcSigmaType -> Pat GhcTc
mkHsWrapPat HsWrapper
wrap Pat GhcTc
res_pat TcSigmaType
pat_ty, a
res) }
else do
{ let theta' :: [TcSigmaType]
theta' = HasCallStack => TCvSubst -> [TcSigmaType] -> [TcSigmaType]
TCvSubst -> [TcSigmaType] -> [TcSigmaType]
substTheta TCvSubst
tenv ([EqSpec] -> [TcSigmaType]
eqSpecPreds [EqSpec]
eq_spec [TcSigmaType] -> [TcSigmaType] -> [TcSigmaType]
forall a. [a] -> [a] -> [a]
++ [TcSigmaType]
theta)
no_equalities :: Bool
no_equalities = [EqSpec] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [EqSpec]
eq_spec Bool -> Bool -> Bool
&& Bool -> Bool
not ((TcSigmaType -> Bool) -> [TcSigmaType] -> Bool
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
any TcSigmaType -> Bool
isEqPred [TcSigmaType]
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")
; [TcId]
given <- [TcSigmaType] -> TcM [TcId]
newEvVars [TcSigmaType]
theta'
; (TcEvBinds
ev_binds, (HsConDetails
(HsPatSigType GhcRn)
(GenLocated SrcSpanAnnA (Pat GhcTc))
(HsRecFields GhcTc (GenLocated SrcSpanAnnA (Pat GhcTc)))
arg_pats', a
res))
<- SkolemInfo
-> [TcId]
-> [TcId]
-> IOEnv
(Env TcGblEnv TcLclEnv)
(HsConDetails
(HsPatSigType GhcRn)
(GenLocated SrcSpanAnnA (Pat GhcTc))
(HsRecFields GhcTc (GenLocated SrcSpanAnnA (Pat GhcTc))),
a)
-> TcM
(TcEvBinds,
(HsConDetails
(HsPatSigType GhcRn)
(GenLocated SrcSpanAnnA (Pat GhcTc))
(HsRecFields GhcTc (GenLocated SrcSpanAnnA (Pat GhcTc))),
a))
forall result.
SkolemInfo
-> [TcId] -> [TcId] -> TcM result -> TcM (TcEvBinds, result)
checkConstraints SkolemInfo
skol_info [TcId]
ex_tvs' [TcId]
given (IOEnv
(Env TcGblEnv TcLclEnv)
(HsConDetails
(HsPatSigType GhcRn)
(GenLocated SrcSpanAnnA (Pat GhcTc))
(HsRecFields GhcTc (GenLocated SrcSpanAnnA (Pat GhcTc))),
a)
-> TcM
(TcEvBinds,
(HsConDetails
(HsPatSigType GhcRn)
(GenLocated SrcSpanAnnA (Pat GhcTc))
(HsRecFields GhcTc (GenLocated SrcSpanAnnA (Pat GhcTc))),
a)))
-> IOEnv
(Env TcGblEnv TcLclEnv)
(HsConDetails
(HsPatSigType GhcRn)
(GenLocated SrcSpanAnnA (Pat GhcTc))
(HsRecFields GhcTc (GenLocated SrcSpanAnnA (Pat GhcTc))),
a)
-> TcM
(TcEvBinds,
(HsConDetails
(HsPatSigType GhcRn)
(GenLocated SrcSpanAnnA (Pat GhcTc))
(HsRecFields GhcTc (GenLocated SrcSpanAnnA (Pat GhcTc))),
a))
forall a b. (a -> b) -> a -> b
$
ConLike
-> [Scaled TcSigmaType]
-> TCvSubst
-> PatEnv
-> HsConPatDetails GhcRn
-> TcM a
-> TcM (HsConPatDetails GhcTc, a)
ConLike
-> [Scaled TcSigmaType]
-> TCvSubst
-> Checker (HsConPatDetails GhcRn) (HsConPatDetails GhcTc)
tcConArgs (DataCon -> ConLike
RealDataCon DataCon
data_con) [Scaled TcSigmaType]
arg_tys_scaled TCvSubst
tenv PatEnv
penv HsConPatDetails GhcRn
arg_pats TcM a
thing_inside
; let res_pat :: Pat GhcTc
res_pat = ConPat :: forall p.
XConPat p -> XRec p (ConLikeP p) -> HsConPatDetails p -> Pat p
ConPat
{ pat_con :: XRec GhcTc (ConLikeP GhcTc)
pat_con = GenLocated SrcSpanAnnN ConLike
XRec GhcTc (ConLikeP GhcTc)
header
, pat_args :: HsConPatDetails GhcTc
pat_args = HsConDetails
(HsPatSigType GhcRn)
(GenLocated SrcSpanAnnA (Pat GhcTc))
(HsRecFields GhcTc (GenLocated SrcSpanAnnA (Pat GhcTc)))
HsConPatDetails GhcTc
arg_pats'
, pat_con_ext :: XConPat GhcTc
pat_con_ext = ConPatTc :: [TcSigmaType]
-> [TcId] -> [TcId] -> TcEvBinds -> HsWrapper -> ConPatTc
ConPatTc
{ cpt_tvs :: [TcId]
cpt_tvs = [TcId]
ex_tvs'
, cpt_dicts :: [TcId]
cpt_dicts = [TcId]
given
, cpt_binds :: TcEvBinds
cpt_binds = TcEvBinds
ev_binds
, cpt_arg_tys :: [TcSigmaType]
cpt_arg_tys = [TcSigmaType]
ctxt_res_tys
, cpt_wrap :: HsWrapper
cpt_wrap = HsWrapper
idHsWrapper
}
}
; (Pat GhcTc, a) -> TcM (Pat GhcTc, a)
forall (m :: * -> *) a. Monad m => a -> m a
return (HsWrapper -> Pat GhcTc -> TcSigmaType -> Pat GhcTc
mkHsWrapPat HsWrapper
wrap Pat GhcTc
res_pat TcSigmaType
pat_ty, a
res)
} }
tcPatSynPat :: PatEnv -> LocatedN Name -> PatSyn
-> Scaled ExpSigmaType
-> HsConPatDetails GhcRn -> TcM a
-> TcM (Pat GhcTc, a)
tcPatSynPat :: PatEnv
-> LocatedN Name
-> PatSyn
-> Scaled ExpSigmaType
-> HsConPatDetails GhcRn
-> TcM a
-> TcM (Pat GhcTc, a)
tcPatSynPat PatEnv
penv (L SrcSpanAnnN
con_span Name
con_name) PatSyn
pat_syn Scaled ExpSigmaType
pat_ty HsConPatDetails GhcRn
arg_pats TcM a
thing_inside
= do { let ([TcId]
univ_tvs, [TcSigmaType]
req_theta, [TcId]
ex_tvs, [TcSigmaType]
prov_theta, [Scaled TcSigmaType]
arg_tys, TcSigmaType
ty) = PatSyn
-> ([TcId], [TcSigmaType], [TcId], [TcSigmaType],
[Scaled TcSigmaType], TcSigmaType)
patSynSig PatSyn
pat_syn
; (TCvSubst
subst, [TcId]
univ_tvs') <- [TcId] -> TcM (TCvSubst, [TcId])
newMetaTyVars [TcId]
univ_tvs
; let all_arg_tys :: [TcSigmaType]
all_arg_tys = TcSigmaType
ty TcSigmaType -> [TcSigmaType] -> [TcSigmaType]
forall a. a -> [a] -> [a]
: [TcSigmaType]
prov_theta [TcSigmaType] -> [TcSigmaType] -> [TcSigmaType]
forall a. [a] -> [a] -> [a]
++ ((Scaled TcSigmaType -> TcSigmaType)
-> [Scaled TcSigmaType] -> [TcSigmaType]
forall a b. (a -> b) -> [a] -> [b]
map Scaled TcSigmaType -> TcSigmaType
forall a. Scaled a -> a
scaledThing [Scaled TcSigmaType]
arg_tys)
; [TcId] -> [TcSigmaType] -> PatEnv -> TcRn ()
checkExistentials [TcId]
ex_tvs [TcSigmaType]
all_arg_tys PatEnv
penv
; (TCvSubst
tenv, [TcId]
ex_tvs') <- TCvSubst -> [TcId] -> TcM (TCvSubst, [TcId])
tcInstSuperSkolTyVarsX TCvSubst
subst [TcId]
ex_tvs
; let ty' :: TcSigmaType
ty' = HasCallStack => TCvSubst -> TcSigmaType -> TcSigmaType
TCvSubst -> TcSigmaType -> TcSigmaType
substTy TCvSubst
tenv TcSigmaType
ty
arg_tys' :: [Scaled TcSigmaType]
arg_tys' = HasCallStack =>
TCvSubst -> [Scaled TcSigmaType] -> [Scaled TcSigmaType]
TCvSubst -> [Scaled TcSigmaType] -> [Scaled TcSigmaType]
substScaledTys TCvSubst
tenv [Scaled TcSigmaType]
arg_tys
pat_mult :: TcSigmaType
pat_mult = Scaled ExpSigmaType -> TcSigmaType
forall a. Scaled a -> TcSigmaType
scaledMult Scaled ExpSigmaType
pat_ty
arg_tys_scaled :: [Scaled TcSigmaType]
arg_tys_scaled = (Scaled TcSigmaType -> Scaled TcSigmaType)
-> [Scaled TcSigmaType] -> [Scaled TcSigmaType]
forall a b. (a -> b) -> [a] -> [b]
map (TcSigmaType -> Scaled TcSigmaType -> Scaled TcSigmaType
forall a. TcSigmaType -> Scaled a -> Scaled a
scaleScaled TcSigmaType
pat_mult) [Scaled TcSigmaType]
arg_tys'
prov_theta' :: [TcSigmaType]
prov_theta' = HasCallStack => TCvSubst -> [TcSigmaType] -> [TcSigmaType]
TCvSubst -> [TcSigmaType] -> [TcSigmaType]
substTheta TCvSubst
tenv [TcSigmaType]
prov_theta
req_theta' :: [TcSigmaType]
req_theta' = HasCallStack => TCvSubst -> [TcSigmaType] -> [TcSigmaType]
TCvSubst -> [TcSigmaType] -> [TcSigmaType]
substTheta TCvSubst
tenv [TcSigmaType]
req_theta
; HsWrapper
mult_wrap <- Scaled ExpSigmaType -> TcM HsWrapper
forall a. Scaled a -> TcM HsWrapper
checkManyPattern Scaled ExpSigmaType
pat_ty
; HsWrapper
wrap <- PatEnv -> ExpSigmaType -> TcSigmaType -> TcM HsWrapper
tc_sub_type PatEnv
penv (Scaled ExpSigmaType -> ExpSigmaType
forall a. Scaled a -> a
scaledThing Scaled ExpSigmaType
pat_ty) TcSigmaType
ty'
; String -> SDoc -> TcRn ()
traceTc String
"tcPatSynPat" (PatSyn -> SDoc
forall a. Outputable a => a -> SDoc
ppr PatSyn
pat_syn SDoc -> SDoc -> SDoc
$$
Scaled ExpSigmaType -> SDoc
forall a. Outputable a => a -> SDoc
ppr Scaled ExpSigmaType
pat_ty SDoc -> SDoc -> SDoc
$$
TcSigmaType -> SDoc
forall a. Outputable a => a -> SDoc
ppr TcSigmaType
ty' SDoc -> SDoc -> SDoc
$$
[TcId] -> SDoc
forall a. Outputable a => a -> SDoc
ppr [TcId]
ex_tvs' SDoc -> SDoc -> SDoc
$$
[TcSigmaType] -> SDoc
forall a. Outputable a => a -> SDoc
ppr [TcSigmaType]
prov_theta' SDoc -> SDoc -> SDoc
$$
[TcSigmaType] -> SDoc
forall a. Outputable a => a -> SDoc
ppr [TcSigmaType]
req_theta' SDoc -> SDoc -> SDoc
$$
[Scaled TcSigmaType] -> SDoc
forall a. Outputable a => a -> SDoc
ppr [Scaled TcSigmaType]
arg_tys')
; [TcId]
prov_dicts' <- [TcSigmaType] -> TcM [TcId]
newEvVars [TcSigmaType]
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 -> [TcSigmaType] -> [TcSigmaType] -> TcM HsWrapper
instCall (Name -> CtOrigin
OccurrenceOf Name
con_name) ([TcId] -> [TcSigmaType]
mkTyVarTys [TcId]
univ_tvs') [TcSigmaType]
req_theta'
; String -> SDoc -> TcRn ()
traceTc String
"instCall" (HsWrapper -> SDoc
forall a. Outputable a => a -> SDoc
ppr HsWrapper
req_wrap)
; String -> SDoc -> TcRn ()
traceTc String
"checkConstraints {" SDoc
Outputable.empty
; (TcEvBinds
ev_binds, (HsConDetails
(HsPatSigType GhcRn)
(GenLocated SrcSpanAnnA (Pat GhcTc))
(HsRecFields GhcTc (GenLocated SrcSpanAnnA (Pat GhcTc)))
arg_pats', a
res))
<- SkolemInfo
-> [TcId]
-> [TcId]
-> TcM
(HsConDetails
(HsPatSigType GhcRn)
(GenLocated SrcSpanAnnA (Pat GhcTc))
(HsRecFields GhcTc (GenLocated SrcSpanAnnA (Pat GhcTc))),
a)
-> TcM
(TcEvBinds,
(HsConDetails
(HsPatSigType GhcRn)
(GenLocated SrcSpanAnnA (Pat GhcTc))
(HsRecFields GhcTc (GenLocated SrcSpanAnnA (Pat GhcTc))),
a))
forall result.
SkolemInfo
-> [TcId] -> [TcId] -> TcM result -> TcM (TcEvBinds, result)
checkConstraints SkolemInfo
skol_info [TcId]
ex_tvs' [TcId]
prov_dicts' (TcM
(HsConDetails
(HsPatSigType GhcRn)
(GenLocated SrcSpanAnnA (Pat GhcTc))
(HsRecFields GhcTc (GenLocated SrcSpanAnnA (Pat GhcTc))),
a)
-> TcM
(TcEvBinds,
(HsConDetails
(HsPatSigType GhcRn)
(GenLocated SrcSpanAnnA (Pat GhcTc))
(HsRecFields GhcTc (GenLocated SrcSpanAnnA (Pat GhcTc))),
a)))
-> TcM
(HsConDetails
(HsPatSigType GhcRn)
(GenLocated SrcSpanAnnA (Pat GhcTc))
(HsRecFields GhcTc (GenLocated SrcSpanAnnA (Pat GhcTc))),
a)
-> TcM
(TcEvBinds,
(HsConDetails
(HsPatSigType GhcRn)
(GenLocated SrcSpanAnnA (Pat GhcTc))
(HsRecFields GhcTc (GenLocated SrcSpanAnnA (Pat GhcTc))),
a))
forall a b. (a -> b) -> a -> b
$
ConLike
-> [Scaled TcSigmaType]
-> TCvSubst
-> PatEnv
-> HsConPatDetails GhcRn
-> TcM a
-> TcM (HsConPatDetails GhcTc, a)
ConLike
-> [Scaled TcSigmaType]
-> TCvSubst
-> Checker (HsConPatDetails GhcRn) (HsConPatDetails GhcTc)
tcConArgs (PatSyn -> ConLike
PatSynCon PatSyn
pat_syn) [Scaled TcSigmaType]
arg_tys_scaled TCvSubst
tenv PatEnv
penv HsConPatDetails GhcRn
arg_pats TcM a
thing_inside
; String -> SDoc -> TcRn ()
traceTc String
"checkConstraints }" (TcEvBinds -> SDoc
forall a. Outputable a => a -> SDoc
ppr TcEvBinds
ev_binds)
; let res_pat :: Pat GhcTc
res_pat = ConPat :: forall p.
XConPat p -> XRec p (ConLikeP p) -> HsConPatDetails p -> Pat p
ConPat { pat_con :: XRec GhcTc (ConLikeP GhcTc)
pat_con = SrcSpanAnnN -> ConLike -> GenLocated SrcSpanAnnN ConLike
forall l e. l -> e -> GenLocated l e
L SrcSpanAnnN
con_span (ConLike -> GenLocated SrcSpanAnnN ConLike)
-> ConLike -> GenLocated SrcSpanAnnN ConLike
forall a b. (a -> b) -> a -> b
$ PatSyn -> ConLike
PatSynCon PatSyn
pat_syn
, pat_args :: HsConPatDetails GhcTc
pat_args = HsConDetails
(HsPatSigType GhcRn)
(GenLocated SrcSpanAnnA (Pat GhcTc))
(HsRecFields GhcTc (GenLocated SrcSpanAnnA (Pat GhcTc)))
HsConPatDetails GhcTc
arg_pats'
, pat_con_ext :: XConPat GhcTc
pat_con_ext = ConPatTc :: [TcSigmaType]
-> [TcId] -> [TcId] -> TcEvBinds -> HsWrapper -> ConPatTc
ConPatTc
{ cpt_tvs :: [TcId]
cpt_tvs = [TcId]
ex_tvs'
, cpt_dicts :: [TcId]
cpt_dicts = [TcId]
prov_dicts'
, cpt_binds :: TcEvBinds
cpt_binds = TcEvBinds
ev_binds
, cpt_arg_tys :: [TcSigmaType]
cpt_arg_tys = [TcId] -> [TcSigmaType]
mkTyVarTys [TcId]
univ_tvs'
, cpt_wrap :: HsWrapper
cpt_wrap = HsWrapper
req_wrap
}
}
; TcSigmaType
pat_ty <- ExpSigmaType -> TcM TcSigmaType
readExpType (Scaled ExpSigmaType -> ExpSigmaType
forall a. Scaled a -> a
scaledThing Scaled ExpSigmaType
pat_ty)
; (Pat GhcTc, a) -> TcM (Pat GhcTc, a)
forall (m :: * -> *) a. Monad m => a -> m a
return (HsWrapper -> Pat GhcTc -> TcSigmaType -> Pat GhcTc
mkHsWrapPat (HsWrapper
wrap HsWrapper -> HsWrapper -> HsWrapper
<.> HsWrapper
mult_wrap) Pat GhcTc
res_pat TcSigmaType
pat_ty, a
res) }
matchExpectedPatTy :: (TcRhoType -> TcM (TcCoercionN, a))
-> PatEnv -> ExpSigmaType -> TcM (HsWrapper, a)
matchExpectedPatTy :: (TcSigmaType -> TcM (TcCoercionN, a))
-> PatEnv -> ExpSigmaType -> TcM (HsWrapper, a)
matchExpectedPatTy TcSigmaType -> TcM (TcCoercionN, a)
inner_match (PE { pe_orig :: PatEnv -> CtOrigin
pe_orig = CtOrigin
orig }) ExpSigmaType
pat_ty
= do { TcSigmaType
pat_ty <- ExpSigmaType -> TcM TcSigmaType
expTypeToType ExpSigmaType
pat_ty
; (HsWrapper
wrap, TcSigmaType
pat_rho) <- CtOrigin -> TcSigmaType -> TcM (HsWrapper, TcSigmaType)
topInstantiate CtOrigin
orig TcSigmaType
pat_ty
; (TcCoercionN
co, a
res) <- TcSigmaType -> TcM (TcCoercionN, a)
inner_match TcSigmaType
pat_rho
; String -> SDoc -> TcRn ()
traceTc String
"matchExpectedPatTy" (TcSigmaType -> SDoc
forall a. Outputable a => a -> SDoc
ppr TcSigmaType
pat_ty SDoc -> SDoc -> SDoc
$$ HsWrapper -> SDoc
forall a. Outputable a => a -> SDoc
ppr HsWrapper
wrap)
; (HsWrapper, a) -> TcM (HsWrapper, a)
forall (m :: * -> *) a. Monad m => a -> m a
return (TcCoercionN -> HsWrapper
mkWpCastN (TcCoercionN -> TcCoercionN
mkTcSymCo TcCoercionN
co) HsWrapper -> HsWrapper -> HsWrapper
<.> HsWrapper
wrap, a
res) }
matchExpectedConTy :: PatEnv
-> TyCon
-> Scaled ExpSigmaType
-> TcM (HsWrapper, [TcSigmaType])
matchExpectedConTy :: PatEnv
-> TyCon -> Scaled ExpSigmaType -> TcM (HsWrapper, [TcSigmaType])
matchExpectedConTy (PE { pe_orig :: PatEnv -> CtOrigin
pe_orig = CtOrigin
orig }) TyCon
data_tc Scaled ExpSigmaType
exp_pat_ty
| Just (TyCon
fam_tc, [TcSigmaType]
fam_args, CoAxiom Unbranched
co_tc) <- TyCon -> Maybe (TyCon, [TcSigmaType], CoAxiom Unbranched)
tyConFamInstSig_maybe TyCon
data_tc
= do { TcSigmaType
pat_ty <- ExpSigmaType -> TcM TcSigmaType
expTypeToType (Scaled ExpSigmaType -> ExpSigmaType
forall a. Scaled a -> a
scaledThing Scaled ExpSigmaType
exp_pat_ty)
; (HsWrapper
wrap, TcSigmaType
pat_rho) <- CtOrigin -> TcSigmaType -> TcM (HsWrapper, TcSigmaType)
topInstantiate CtOrigin
orig TcSigmaType
pat_ty
; (TCvSubst
subst, [TcId]
tvs') <- [TcId] -> TcM (TCvSubst, [TcId])
newMetaTyVars (TyCon -> [TcId]
tyConTyVars TyCon
data_tc)
; String -> SDoc -> TcRn ()
traceTc String
"matchExpectedConTy" ([SDoc] -> SDoc
vcat [TyCon -> SDoc
forall a. Outputable a => a -> SDoc
ppr TyCon
data_tc,
[TcId] -> SDoc
forall a. Outputable a => a -> SDoc
ppr (TyCon -> [TcId]
tyConTyVars TyCon
data_tc),
TyCon -> SDoc
forall a. Outputable a => a -> SDoc
ppr TyCon
fam_tc, [TcSigmaType] -> SDoc
forall a. Outputable a => a -> SDoc
ppr [TcSigmaType]
fam_args,
Scaled ExpSigmaType -> SDoc
forall a. Outputable a => a -> SDoc
ppr Scaled ExpSigmaType
exp_pat_ty,
TcSigmaType -> SDoc
forall a. Outputable a => a -> SDoc
ppr TcSigmaType
pat_ty,
TcSigmaType -> SDoc
forall a. Outputable a => a -> SDoc
ppr TcSigmaType
pat_rho, HsWrapper -> SDoc
forall a. Outputable a => a -> SDoc
ppr HsWrapper
wrap])
; TcCoercionN
co1 <- Maybe SDoc -> TcSigmaType -> TcSigmaType -> TcM TcCoercionN
unifyType Maybe SDoc
forall a. Maybe a
Nothing (TyCon -> [TcSigmaType] -> TcSigmaType
mkTyConApp TyCon
fam_tc (HasCallStack => TCvSubst -> [TcSigmaType] -> [TcSigmaType]
TCvSubst -> [TcSigmaType] -> [TcSigmaType]
substTys TCvSubst
subst [TcSigmaType]
fam_args)) TcSigmaType
pat_rho
; let tys' :: [TcSigmaType]
tys' = [TcId] -> [TcSigmaType]
mkTyVarTys [TcId]
tvs'
co2 :: TcCoercionN
co2 = CoAxiom Unbranched -> [TcSigmaType] -> [TcCoercionN] -> TcCoercionN
mkTcUnbranchedAxInstCo CoAxiom Unbranched
co_tc [TcSigmaType]
tys' []
full_co :: TcCoercionN
full_co = HasDebugCallStack => TcCoercionN -> TcCoercionN
TcCoercionN -> TcCoercionN
mkTcSubCo (TcCoercionN -> TcCoercionN
mkTcSymCo TcCoercionN
co1) TcCoercionN -> TcCoercionN -> TcCoercionN
`mkTcTransCo` TcCoercionN
co2
; (HsWrapper, [TcSigmaType]) -> TcM (HsWrapper, [TcSigmaType])
forall (m :: * -> *) a. Monad m => a -> m a
return ( TcCoercionN -> HsWrapper
mkWpCastR TcCoercionN
full_co HsWrapper -> HsWrapper -> HsWrapper
<.> HsWrapper
wrap, [TcSigmaType]
tys') }
| Bool
otherwise
= do { TcSigmaType
pat_ty <- ExpSigmaType -> TcM TcSigmaType
expTypeToType (Scaled ExpSigmaType -> ExpSigmaType
forall a. Scaled a -> a
scaledThing Scaled ExpSigmaType
exp_pat_ty)
; (HsWrapper
wrap, TcSigmaType
pat_rho) <- CtOrigin -> TcSigmaType -> TcM (HsWrapper, TcSigmaType)
topInstantiate CtOrigin
orig TcSigmaType
pat_ty
; (TcCoercionN
coi, [TcSigmaType]
tys) <- TyCon -> TcSigmaType -> TcM (TcCoercionN, [TcSigmaType])
matchExpectedTyConApp TyCon
data_tc TcSigmaType
pat_rho
; (HsWrapper, [TcSigmaType]) -> TcM (HsWrapper, [TcSigmaType])
forall (m :: * -> *) a. Monad m => a -> m a
return (TcCoercionN -> HsWrapper
mkWpCastN (TcCoercionN -> TcCoercionN
mkTcSymCo TcCoercionN
coi) HsWrapper -> HsWrapper -> HsWrapper
<.> HsWrapper
wrap, [TcSigmaType]
tys) }
tcConArgs :: ConLike
-> [Scaled TcSigmaType]
-> TCvSubst
-> Checker (HsConPatDetails GhcRn) (HsConPatDetails GhcTc)
tcConArgs :: ConLike
-> [Scaled TcSigmaType]
-> TCvSubst
-> Checker (HsConPatDetails GhcRn) (HsConPatDetails GhcTc)
tcConArgs ConLike
con_like [Scaled TcSigmaType]
arg_tys TCvSubst
tenv PatEnv
penv HsConPatDetails GhcRn
con_args TcM r
thing_inside = case HsConPatDetails GhcRn
con_args of
PrefixCon [HsPatSigType (NoGhcTc GhcRn)]
type_args [LPat GhcRn]
arg_pats -> do
{ Bool -> SDoc -> TcRn ()
checkTc (Int
con_arity Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
no_of_args)
(SDoc -> ConLike -> Int -> Int -> SDoc
forall a. Outputable a => SDoc -> a -> Int -> Int -> SDoc
arityErr (String -> SDoc
text String
"constructor") ConLike
con_like Int
con_arity Int
no_of_args)
; let con_binders :: [InvisTVBinder]
con_binders = ConLike -> [InvisTVBinder]
conLikeUserTyVarBinders ConLike
con_like
; Bool -> SDoc -> TcRn ()
checkTc ([HsPatSigType GhcRn]
[HsPatSigType (NoGhcTc GhcRn)]
type_args [HsPatSigType GhcRn] -> [InvisTVBinder] -> Bool
forall a b. [a] -> [b] -> Bool
`leLength` [InvisTVBinder]
con_binders)
(ConLike -> Int -> Int -> SDoc
conTyArgArityErr ConLike
con_like ([InvisTVBinder] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [InvisTVBinder]
con_binders) ([HsPatSigType GhcRn] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [HsPatSigType GhcRn]
[HsPatSigType (NoGhcTc GhcRn)]
type_args))
; let pats_w_tys :: [(GenLocated SrcSpanAnnA (Pat GhcRn), Scaled TcSigmaType)]
pats_w_tys = String
-> [GenLocated SrcSpanAnnA (Pat GhcRn)]
-> [Scaled TcSigmaType]
-> [(GenLocated SrcSpanAnnA (Pat GhcRn), Scaled TcSigmaType)]
forall a b. String -> [a] -> [b] -> [(a, b)]
zipEqual String
"tcConArgs" [GenLocated SrcSpanAnnA (Pat GhcRn)]
[LPat GhcRn]
arg_pats [Scaled TcSigmaType]
arg_tys
; ([TcSigmaType]
type_args', ([GenLocated SrcSpanAnnA (Pat GhcTc)]
arg_pats', r
res))
<- Checker (HsPatSigType GhcRn) TcSigmaType
-> PatEnv
-> [HsPatSigType GhcRn]
-> TcM ([GenLocated SrcSpanAnnA (Pat GhcTc)], r)
-> TcM ([TcSigmaType], ([GenLocated SrcSpanAnnA (Pat GhcTc)], r))
forall inp out. Checker inp out -> Checker [inp] [out]
tcMultiple Checker (HsPatSigType GhcRn) TcSigmaType
tcConTyArg PatEnv
penv [HsPatSigType GhcRn]
[HsPatSigType (NoGhcTc GhcRn)]
type_args (TcM ([GenLocated SrcSpanAnnA (Pat GhcTc)], r)
-> TcM ([TcSigmaType], ([GenLocated SrcSpanAnnA (Pat GhcTc)], r)))
-> TcM ([GenLocated SrcSpanAnnA (Pat GhcTc)], r)
-> TcM ([TcSigmaType], ([GenLocated SrcSpanAnnA (Pat GhcTc)], r))
forall a b. (a -> b) -> a -> b
$
Checker
(GenLocated SrcSpanAnnA (Pat GhcRn), Scaled TcSigmaType)
(GenLocated SrcSpanAnnA (Pat GhcTc))
-> PatEnv
-> [(GenLocated SrcSpanAnnA (Pat GhcRn), Scaled TcSigmaType)]
-> TcM r
-> TcM ([GenLocated SrcSpanAnnA (Pat GhcTc)], r)
forall inp out. Checker inp out -> Checker [inp] [out]
tcMultiple Checker
(GenLocated SrcSpanAnnA (Pat GhcRn), Scaled TcSigmaType)
(GenLocated SrcSpanAnnA (Pat GhcTc))
Checker (LPat GhcRn, Scaled TcSigmaType) (LPat GhcTc)
tcConArg PatEnv
penv [(GenLocated SrcSpanAnnA (Pat GhcRn), Scaled TcSigmaType)]
pats_w_tys TcM r
thing_inside
; [TcCoercionN]
_ <- (TcSigmaType -> TcSigmaType -> TcM TcCoercionN)
-> [TcSigmaType]
-> [TcSigmaType]
-> IOEnv (Env TcGblEnv TcLclEnv) [TcCoercionN]
forall (m :: * -> *) a b c.
Applicative m =>
(a -> b -> m c) -> [a] -> [b] -> m [c]
zipWithM (Maybe SDoc -> TcSigmaType -> TcSigmaType -> TcM TcCoercionN
unifyType Maybe SDoc
forall a. Maybe a
Nothing) [TcSigmaType]
type_args' (TCvSubst -> [TcId] -> [TcSigmaType]
substTyVars TCvSubst
tenv ([TcId] -> [TcSigmaType]) -> [TcId] -> [TcSigmaType]
forall a b. (a -> b) -> a -> b
$
[InvisTVBinder] -> [TcId]
forall tv argf. [VarBndr tv argf] -> [tv]
binderVars [InvisTVBinder]
con_binders)
; (HsConDetails
(HsPatSigType GhcRn)
(GenLocated SrcSpanAnnA (Pat GhcTc))
(HsRecFields GhcTc (GenLocated SrcSpanAnnA (Pat GhcTc))),
r)
-> IOEnv
(Env TcGblEnv TcLclEnv)
(HsConDetails
(HsPatSigType GhcRn)
(GenLocated SrcSpanAnnA (Pat GhcTc))
(HsRecFields GhcTc (GenLocated SrcSpanAnnA (Pat GhcTc))),
r)
forall (m :: * -> *) a. Monad m => a -> m a
return ([HsPatSigType GhcRn]
-> [GenLocated SrcSpanAnnA (Pat GhcTc)]
-> HsConDetails
(HsPatSigType GhcRn)
(GenLocated SrcSpanAnnA (Pat GhcTc))
(HsRecFields GhcTc (GenLocated SrcSpanAnnA (Pat GhcTc)))
forall tyarg arg rec.
[tyarg] -> [arg] -> HsConDetails tyarg arg rec
PrefixCon [HsPatSigType GhcRn]
[HsPatSigType (NoGhcTc GhcRn)]
type_args [GenLocated SrcSpanAnnA (Pat GhcTc)]
arg_pats', r
res) }
where
con_arity :: Int
con_arity = ConLike -> Int
conLikeArity ConLike
con_like
no_of_args :: Int
no_of_args = [GenLocated SrcSpanAnnA (Pat GhcRn)] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [GenLocated SrcSpanAnnA (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
== Int
2)
(SDoc -> ConLike -> Int -> Int -> SDoc
forall a. Outputable a => SDoc -> a -> Int -> Int -> SDoc
arityErr (String -> SDoc
text String
"constructor") ConLike
con_like Int
con_arity Int
2)
; let [Scaled TcSigmaType
arg_ty1,Scaled TcSigmaType
arg_ty2] = [Scaled TcSigmaType]
arg_tys
; ([GenLocated SrcSpanAnnA (Pat GhcTc)
p1',GenLocated SrcSpanAnnA (Pat GhcTc)
p2'], r
res) <- Checker
(GenLocated SrcSpanAnnA (Pat GhcRn), Scaled TcSigmaType)
(GenLocated SrcSpanAnnA (Pat GhcTc))
-> PatEnv
-> [(GenLocated SrcSpanAnnA (Pat GhcRn), Scaled TcSigmaType)]
-> TcM r
-> TcM ([GenLocated SrcSpanAnnA (Pat GhcTc)], r)
forall inp out. Checker inp out -> Checker [inp] [out]
tcMultiple Checker
(GenLocated SrcSpanAnnA (Pat GhcRn), Scaled TcSigmaType)
(GenLocated SrcSpanAnnA (Pat GhcTc))
Checker (LPat GhcRn, Scaled TcSigmaType) (LPat GhcTc)
tcConArg PatEnv
penv [(GenLocated SrcSpanAnnA (Pat GhcRn)
LPat GhcRn
p1,Scaled TcSigmaType
arg_ty1),(GenLocated SrcSpanAnnA (Pat GhcRn)
LPat GhcRn
p2,Scaled TcSigmaType
arg_ty2)]
TcM r
thing_inside
; (HsConDetails
(HsPatSigType GhcRn)
(GenLocated SrcSpanAnnA (Pat GhcTc))
(HsRecFields GhcTc (GenLocated SrcSpanAnnA (Pat GhcTc))),
r)
-> IOEnv
(Env TcGblEnv TcLclEnv)
(HsConDetails
(HsPatSigType GhcRn)
(GenLocated SrcSpanAnnA (Pat GhcTc))
(HsRecFields GhcTc (GenLocated SrcSpanAnnA (Pat GhcTc))),
r)
forall (m :: * -> *) a. Monad m => a -> m a
return (GenLocated SrcSpanAnnA (Pat GhcTc)
-> GenLocated SrcSpanAnnA (Pat GhcTc)
-> HsConDetails
(HsPatSigType GhcRn)
(GenLocated SrcSpanAnnA (Pat GhcTc))
(HsRecFields GhcTc (GenLocated SrcSpanAnnA (Pat GhcTc)))
forall tyarg arg rec. arg -> arg -> HsConDetails tyarg arg rec
InfixCon GenLocated SrcSpanAnnA (Pat GhcTc)
p1' GenLocated SrcSpanAnnA (Pat GhcTc)
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
{ ([GenLocated
SrcSpanAnnA
(HsRecField'
(FieldOcc GhcTc) (GenLocated SrcSpanAnnA (Pat GhcTc)))]
rpats', r
res) <- Checker
(GenLocated
SrcSpanAnnA
(HsRecField'
(FieldOcc GhcRn) (GenLocated SrcSpanAnnA (Pat GhcRn))))
(GenLocated
SrcSpanAnnA
(HsRecField'
(FieldOcc GhcTc) (GenLocated SrcSpanAnnA (Pat GhcTc))))
-> PatEnv
-> [GenLocated
SrcSpanAnnA
(HsRecField'
(FieldOcc GhcRn) (GenLocated SrcSpanAnnA (Pat GhcRn)))]
-> TcM r
-> TcM
([GenLocated
SrcSpanAnnA
(HsRecField'
(FieldOcc GhcTc) (GenLocated SrcSpanAnnA (Pat GhcTc)))],
r)
forall inp out. Checker inp out -> Checker [inp] [out]
tcMultiple Checker
(GenLocated
SrcSpanAnnA
(HsRecField'
(FieldOcc GhcRn) (GenLocated SrcSpanAnnA (Pat GhcRn))))
(GenLocated
SrcSpanAnnA
(HsRecField'
(FieldOcc GhcTc) (GenLocated SrcSpanAnnA (Pat GhcTc))))
Checker
(LHsRecField GhcRn (LPat GhcRn)) (LHsRecField GhcTc (LPat GhcTc))
tc_field PatEnv
penv [GenLocated
SrcSpanAnnA
(HsRecField'
(FieldOcc GhcRn) (GenLocated SrcSpanAnnA (Pat GhcRn)))]
[LHsRecField GhcRn (LPat GhcRn)]
rpats TcM r
thing_inside
; (HsConDetails
(HsPatSigType GhcRn)
(GenLocated SrcSpanAnnA (Pat GhcTc))
(HsRecFields GhcTc (GenLocated SrcSpanAnnA (Pat GhcTc))),
r)
-> IOEnv
(Env TcGblEnv TcLclEnv)
(HsConDetails
(HsPatSigType GhcRn)
(GenLocated SrcSpanAnnA (Pat GhcTc))
(HsRecFields GhcTc (GenLocated SrcSpanAnnA (Pat GhcTc))),
r)
forall (m :: * -> *) a. Monad m => a -> m a
return (HsRecFields GhcTc (GenLocated SrcSpanAnnA (Pat GhcTc))
-> HsConDetails
(HsPatSigType GhcRn)
(GenLocated SrcSpanAnnA (Pat GhcTc))
(HsRecFields GhcTc (GenLocated SrcSpanAnnA (Pat GhcTc)))
forall tyarg arg rec. rec -> HsConDetails tyarg arg rec
RecCon ([LHsRecField GhcTc (GenLocated SrcSpanAnnA (Pat GhcTc))]
-> Maybe (Located Int)
-> HsRecFields GhcTc (GenLocated SrcSpanAnnA (Pat GhcTc))
forall p arg.
[LHsRecField p arg] -> Maybe (Located Int) -> HsRecFields p arg
HsRecFields [GenLocated
SrcSpanAnnA
(HsRecField'
(FieldOcc GhcTc) (GenLocated SrcSpanAnnA (Pat GhcTc)))]
[LHsRecField GhcTc (GenLocated SrcSpanAnnA (Pat GhcTc))]
rpats' Maybe (Located Int)
dd), r
res) }
where
tc_field :: Checker (LHsRecField GhcRn (LPat GhcRn))
(LHsRecField GhcTc (LPat GhcTc))
tc_field :: PatEnv
-> LHsRecField GhcRn (LPat GhcRn)
-> TcM r
-> TcM (LHsRecField GhcTc (LPat GhcTc), r)
tc_field PatEnv
penv
(L l (HsRecField ann (L loc (FieldOcc sel (L lr rdr))) pat pun))
TcM r
thing_inside
= do { TcId
sel' <- Name -> TcM TcId
tcLookupId Name
XCFieldOcc GhcRn
sel
; Scaled TcSigmaType
pat_ty <- SrcSpan -> TcRn (Scaled TcSigmaType) -> TcRn (Scaled TcSigmaType)
forall a. SrcSpan -> TcRn a -> TcRn a
setSrcSpan SrcSpan
loc (TcRn (Scaled TcSigmaType) -> TcRn (Scaled TcSigmaType))
-> TcRn (Scaled TcSigmaType) -> TcRn (Scaled TcSigmaType)
forall a b. (a -> b) -> a -> b
$ Name -> FieldLabelString -> TcRn (Scaled TcSigmaType)
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)
; (GenLocated SrcSpanAnnA (Pat GhcTc)
pat', r
res) <- PatEnv
-> (LPat GhcRn, Scaled TcSigmaType) -> TcM r -> TcM (LPat GhcTc, r)
Checker (LPat GhcRn, Scaled TcSigmaType) (LPat GhcTc)
tcConArg PatEnv
penv (GenLocated SrcSpanAnnA (Pat GhcRn)
LPat GhcRn
pat, Scaled TcSigmaType
pat_ty) TcM r
thing_inside
; (GenLocated
SrcSpanAnnA
(HsRecField'
(FieldOcc GhcTc) (GenLocated SrcSpanAnnA (Pat GhcTc))),
r)
-> IOEnv
(Env TcGblEnv TcLclEnv)
(GenLocated
SrcSpanAnnA
(HsRecField'
(FieldOcc GhcTc) (GenLocated SrcSpanAnnA (Pat GhcTc))),
r)
forall (m :: * -> *) a. Monad m => a -> m a
return (SrcSpanAnnA
-> HsRecField'
(FieldOcc GhcTc) (GenLocated SrcSpanAnnA (Pat GhcTc))
-> GenLocated
SrcSpanAnnA
(HsRecField' (FieldOcc GhcTc) (GenLocated SrcSpanAnnA (Pat GhcTc)))
forall l e. l -> e -> GenLocated l e
L SrcSpanAnnA
l (XHsRecField (FieldOcc GhcTc)
-> Located (FieldOcc GhcTc)
-> GenLocated SrcSpanAnnA (Pat GhcTc)
-> Bool
-> HsRecField'
(FieldOcc GhcTc) (GenLocated SrcSpanAnnA (Pat GhcTc))
forall id arg.
XHsRecField id -> Located id -> arg -> Bool -> HsRecField' id arg
HsRecField XHsRecField (FieldOcc GhcRn)
XHsRecField (FieldOcc GhcTc)
ann (SrcSpan -> FieldOcc GhcTc -> Located (FieldOcc GhcTc)
forall l e. l -> e -> GenLocated l e
L SrcSpan
loc (XCFieldOcc GhcTc -> LocatedN RdrName -> FieldOcc GhcTc
forall pass. XCFieldOcc pass -> LocatedN RdrName -> FieldOcc pass
FieldOcc TcId
XCFieldOcc GhcTc
sel' (SrcSpanAnnN -> RdrName -> LocatedN RdrName
forall l e. l -> e -> GenLocated l e
L SrcSpanAnnN
lr RdrName
rdr))) GenLocated SrcSpanAnnA (Pat GhcTc)
pat'
Bool
pun), r
res) }
find_field_ty :: Name -> FieldLabelString -> TcM (Scaled TcType)
find_field_ty :: Name -> FieldLabelString -> TcRn (Scaled TcSigmaType)
find_field_ty Name
sel FieldLabelString
lbl
= case [Scaled TcSigmaType
ty | (FieldLabel
fl, Scaled TcSigmaType
ty) <- [(FieldLabel, Scaled TcSigmaType)]
field_tys, FieldLabel -> Name
flSelector FieldLabel
fl Name -> Name -> Bool
forall a. Eq a => a -> a -> Bool
== Name
sel ] of
[] -> SDoc -> TcRn (Scaled TcSigmaType)
forall a. SDoc -> TcRn a
failWith (ConLike -> FieldLabelString -> SDoc
badFieldCon ConLike
con_like FieldLabelString
lbl)
(Scaled TcSigmaType
pat_ty : [Scaled TcSigmaType]
extras) -> do
String -> SDoc -> TcRn ()
traceTc String
"find_field" (Scaled TcSigmaType -> SDoc
forall a. Outputable a => a -> SDoc
ppr Scaled TcSigmaType
pat_ty SDoc -> SDoc -> SDoc
<+> [Scaled TcSigmaType] -> SDoc
forall a. Outputable a => a -> SDoc
ppr [Scaled TcSigmaType]
extras)
ASSERT( null extras ) (return pat_ty)
field_tys :: [(FieldLabel, Scaled TcType)]
field_tys :: [(FieldLabel, Scaled TcSigmaType)]
field_tys = [FieldLabel]
-> [Scaled TcSigmaType] -> [(FieldLabel, Scaled TcSigmaType)]
forall a b. [a] -> [b] -> [(a, b)]
zip (ConLike -> [FieldLabel]
conLikeFieldLabels ConLike
con_like) [Scaled TcSigmaType]
arg_tys
tcConTyArg :: Checker (HsPatSigType GhcRn) TcType
tcConTyArg :: PatEnv -> HsPatSigType GhcRn -> TcM r -> TcM (TcSigmaType, r)
tcConTyArg PatEnv
penv HsPatSigType GhcRn
rn_ty TcM r
thing_inside
= do { ([(Name, TcId)]
sig_wcs, [(Name, TcId)]
sig_ibs, TcSigmaType
arg_ty) <- UserTypeCtxt
-> HoleMode
-> HsPatSigType GhcRn
-> ContextKind
-> TcM ([(Name, TcId)], [(Name, TcId)], TcSigmaType)
tcHsPatSigType UserTypeCtxt
TypeAppCtxt HoleMode
HM_TyAppPat HsPatSigType GhcRn
rn_ty ContextKind
AnyKind
; Bool -> TcRn () -> TcRn ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (Bool -> Bool
not ([(Name, TcId)] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [(Name, TcId)]
sig_ibs) Bool -> Bool -> Bool
&& PatEnv -> Bool
inPatBind PatEnv
penv) (TcRn () -> TcRn ()) -> TcRn () -> TcRn ()
forall a b. (a -> b) -> a -> b
$
SDoc -> TcRn ()
addErr (String -> SDoc
text String
"Binding type variables is not allowed in pattern bindings")
; r
result <- [(Name, TcId)] -> TcM r -> TcM r
forall r. [(Name, TcId)] -> TcM r -> TcM r
tcExtendNameTyVarEnv [(Name, TcId)]
sig_wcs (TcM r -> TcM r) -> TcM r -> TcM r
forall a b. (a -> b) -> a -> b
$
[(Name, TcId)] -> TcM r -> TcM r
forall r. [(Name, TcId)] -> TcM r -> TcM r
tcExtendNameTyVarEnv [(Name, TcId)]
sig_ibs (TcM r -> TcM r) -> TcM r -> TcM r
forall a b. (a -> b) -> a -> b
$
TcM r
thing_inside
; (TcSigmaType, r) -> TcM (TcSigmaType, r)
forall (m :: * -> *) a. Monad m => a -> m a
return (TcSigmaType
arg_ty, r
result) }
tcConArg :: Checker (LPat GhcRn, Scaled TcSigmaType) (LPat GhcTc)
tcConArg :: PatEnv
-> (LPat GhcRn, Scaled TcSigmaType) -> TcM r -> TcM (LPat GhcTc, r)
tcConArg PatEnv
penv (LPat GhcRn
arg_pat, Scaled TcSigmaType
arg_mult TcSigmaType
arg_ty)
= Scaled ExpSigmaType
-> PatEnv -> LPat GhcRn -> TcM r -> TcM (LPat GhcTc, r)
Scaled ExpSigmaType -> Checker (LPat GhcRn) (LPat GhcTc)
tc_lpat (TcSigmaType -> ExpSigmaType -> Scaled ExpSigmaType
forall a. TcSigmaType -> a -> Scaled a
Scaled TcSigmaType
arg_mult (TcSigmaType -> ExpSigmaType
mkCheckExpType TcSigmaType
arg_ty)) PatEnv
penv LPat GhcRn
arg_pat
addDataConStupidTheta :: DataCon -> [TcType] -> TcM ()
addDataConStupidTheta :: DataCon -> [TcSigmaType] -> TcRn ()
addDataConStupidTheta DataCon
data_con [TcSigmaType]
inst_tys
| [TcSigmaType] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [TcSigmaType]
stupid_theta = () -> TcRn ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
| Bool
otherwise = CtOrigin -> [TcSigmaType] -> TcRn ()
instStupidTheta CtOrigin
origin [TcSigmaType]
inst_theta
where
origin :: CtOrigin
origin = Name -> CtOrigin
OccurrenceOf (DataCon -> Name
dataConName DataCon
data_con)
stupid_theta :: [TcSigmaType]
stupid_theta = DataCon -> [TcSigmaType]
dataConStupidTheta DataCon
data_con
univ_tvs :: [TcId]
univ_tvs = DataCon -> [TcId]
dataConUnivTyVars DataCon
data_con
tenv :: TCvSubst
tenv = [TcId] -> [TcSigmaType] -> TCvSubst
HasDebugCallStack => [TcId] -> [TcSigmaType] -> TCvSubst
zipTvSubst [TcId]
univ_tvs ([TcId] -> [TcSigmaType] -> [TcSigmaType]
forall b a. [b] -> [a] -> [a]
takeList [TcId]
univ_tvs [TcSigmaType]
inst_tys)
inst_theta :: [TcSigmaType]
inst_theta = HasCallStack => TCvSubst -> [TcSigmaType] -> [TcSigmaType]
TCvSubst -> [TcSigmaType] -> [TcSigmaType]
substTheta TCvSubst
tenv [TcSigmaType]
stupid_theta
conTyArgArityErr :: ConLike
-> Int
-> Int
-> SDoc
conTyArgArityErr :: ConLike -> Int -> Int -> SDoc
conTyArgArityErr ConLike
con_like Int
expected_number Int
actual_number
= String -> SDoc
text String
"Too many type arguments in constructor pattern for" SDoc -> SDoc -> SDoc
<+> SDoc -> SDoc
quotes (ConLike -> SDoc
forall a. Outputable a => a -> SDoc
ppr ConLike
con_like) SDoc -> SDoc -> SDoc
$$
String -> SDoc
text String
"Expected no more than" SDoc -> SDoc -> SDoc
<+> Int -> SDoc
forall a. Outputable a => a -> SDoc
ppr Int
expected_number SDoc -> SDoc -> SDoc
<> SDoc
semi SDoc -> SDoc -> SDoc
<+> String -> SDoc
text String
"got" SDoc -> SDoc -> SDoc
<+> Int -> SDoc
forall a. Outputable a => a -> SDoc
ppr Int
actual_number
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
ppr Pat GhcRn
pat)
checkExistentials :: [TyVar]
-> [Type]
-> PatEnv -> TcM ()
checkExistentials :: [TcId] -> [TcSigmaType] -> PatEnv -> TcRn ()
checkExistentials [TcId]
ex_tvs [TcSigmaType]
tys PatEnv
_
| (TcId -> Bool) -> [TcId] -> Bool
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
all (Bool -> Bool
not (Bool -> Bool) -> (TcId -> Bool) -> TcId -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (TcId -> VarSet -> Bool
`elemVarSet` [TcSigmaType] -> VarSet
tyCoVarsOfTypes [TcSigmaType]
tys)) [TcId]
ex_tvs = () -> TcRn ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
checkExistentials [TcId]
_ [TcSigmaType]
_ (PE { pe_ctxt :: PatEnv -> PatCtxt
pe_ctxt = LetPat {}}) = () -> TcRn ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
checkExistentials [TcId]
_ [TcSigmaType]
_ (PE { pe_ctxt :: PatEnv -> PatCtxt
pe_ctxt = LamPat HsMatchContext GhcRn
ProcExpr }) = SDoc -> TcRn ()
forall a. SDoc -> TcRn a
failWithTc SDoc
existentialProcPat
checkExistentials [TcId]
_ [TcSigmaType]
_ (PE { pe_lazy :: PatEnv -> Bool
pe_lazy = Bool
True }) = SDoc -> TcRn ()
forall a. SDoc -> TcRn a
failWithTc SDoc
existentialLazyPat
checkExistentials [TcId]
_ [TcSigmaType]
_ PatEnv
_ = () -> TcRn ()
forall (m :: * -> *) a. Monad m => a -> m a
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
ppr ConLike
con),
String -> SDoc
text String
"does not have field", SDoc -> SDoc
quotes (FieldLabelString -> SDoc
forall a. Outputable a => a -> SDoc
ppr FieldLabelString
field)]
polyPatSig :: TcType -> SDoc
polyPatSig :: TcSigmaType -> SDoc
polyPatSig TcSigmaType
sig_ty
= SDoc -> Int -> SDoc -> SDoc
hang (String -> SDoc
text String
"Illegal polymorphic type signature in pattern:")
Int
2 (TcSigmaType -> SDoc
forall a. Outputable a => a -> SDoc
ppr TcSigmaType
sig_ty)