{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE LambdaCase #-}
{-# 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
)
where
import GHC.Prelude
import {-# SOURCE #-} GHC.Tc.Gen.Expr( tcSyntaxOp, tcSyntaxOpGen, tcInferRho )
import GHC.Hs
import GHC.Hs.Syn.Type
import GHC.Rename.Utils
import GHC.Tc.Errors.Types
import GHC.Tc.Gen.Sig( TcPragEnv, lookupPragEnv, addInlinePrags )
import GHC.Tc.Utils.Monad
import GHC.Tc.Utils.Instantiate
import GHC.Types.FieldLabel
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.Concrete ( hasFixedRuntimeRep_syntactic )
import GHC.Tc.Utils.Env
import GHC.Tc.Utils.TcMType
import GHC.Tc.Zonk.TcType
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.Coercion
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.DynFlags
import GHC.Types.SrcLoc
import GHC.Types.Var.Set
import GHC.Utils.Misc
import GHC.Utils.Outputable as Outputable
import GHC.Utils.Panic
import GHC.Utils.Panic.Plain
import qualified GHC.LanguageExtensions as LangExt
import Control.Arrow ( second )
import Control.Monad
import GHC.Data.FastString
import qualified Data.List.NonEmpty as NE
import GHC.Data.List.SetOps ( getNth )
import Language.Haskell.Syntax.Basic (FieldLabelString(..))
import Data.List( partition )
tcLetPat :: (Name -> Maybe TcId)
-> LetBndrSpec
-> LPat GhcRn -> Scaled ExpSigmaTypeFRR
-> TcM a
-> TcM (LPat GhcTc, a)
tcLetPat :: forall a.
(Name -> Maybe TyCoVar)
-> LetBndrSpec
-> LPat GhcRn
-> Scaled ExpSigmaTypeFRR
-> TcM a
-> TcM (LPat GhcTc, a)
tcLetPat Name -> Maybe TyCoVar
sig_fn LetBndrSpec
no_gen LPat GhcRn
pat Scaled ExpSigmaTypeFRR
pat_ty TcM a
thing_inside
= do { TcLevel
bind_lvl <- TcM TcLevel
getTcLevel
; let ctxt :: PatCtxt
ctxt = LetPat { pc_lvl :: TcLevel
pc_lvl = TcLevel
bind_lvl
, pc_sig_fn :: Name -> Maybe TyCoVar
pc_sig_fn = Name -> Maybe TyCoVar
sig_fn
, pc_new :: LetBndrSpec
pc_new = LetBndrSpec
no_gen }
penv :: PatEnv
penv = PE { pe_lazy :: Bool
pe_lazy = Bool
True
, pe_ctxt :: PatCtxt
pe_ctxt = PatCtxt
ctxt
, pe_orig :: CtOrigin
pe_orig = CtOrigin
PatOrigin }
; Scaled ExpSigmaTypeFRR -> Checker (LPat GhcRn) (LPat GhcTc)
tc_lpat Scaled ExpSigmaTypeFRR
pat_ty PatEnv
penv LPat GhcRn
pat TcM a
thing_inside }
tcPats :: HsMatchContext GhcTc
-> [LPat GhcRn]
-> [Scaled ExpSigmaTypeFRR]
-> TcM a
-> TcM ([LPat GhcTc], a)
tcPats :: forall a.
HsMatchContext GhcTc
-> [LPat GhcRn]
-> [Scaled ExpSigmaTypeFRR]
-> TcM a
-> TcM ([LPat GhcTc], a)
tcPats HsMatchContext GhcTc
ctxt [LPat GhcRn]
pats [Scaled ExpSigmaTypeFRR]
pat_tys TcM a
thing_inside
= [Scaled ExpSigmaTypeFRR] -> Checker [LPat GhcRn] [LPat GhcTc]
tc_lpats [Scaled ExpSigmaTypeFRR]
pat_tys PatEnv
penv [LPat GhcRn]
pats TcM a
thing_inside
where
penv :: PatEnv
penv = PE { pe_lazy :: Bool
pe_lazy = Bool
False, pe_ctxt :: PatCtxt
pe_ctxt = HsMatchContext GhcTc -> PatCtxt
LamPat HsMatchContext GhcTc
ctxt, pe_orig :: CtOrigin
pe_orig = CtOrigin
PatOrigin }
tcInferPat :: FixedRuntimeRepContext
-> HsMatchContext GhcTc
-> LPat GhcRn
-> TcM a
-> TcM ((LPat GhcTc, a), TcSigmaTypeFRR)
tcInferPat :: forall a.
FixedRuntimeRepContext
-> HsMatchContext GhcTc
-> LPat GhcRn
-> TcM a
-> TcM ((LPat GhcTc, a), Type)
tcInferPat FixedRuntimeRepContext
frr_orig HsMatchContext GhcTc
ctxt LPat GhcRn
pat TcM a
thing_inside
= FixedRuntimeRepContext
-> (ExpSigmaTypeFRR -> TcM (LPat GhcTc, a))
-> TcM ((LPat GhcTc, a), Type)
forall a.
FixedRuntimeRepContext
-> (ExpSigmaTypeFRR -> TcM a) -> TcM (a, Type)
tcInferFRR FixedRuntimeRepContext
frr_orig ((ExpSigmaTypeFRR -> TcM (LPat GhcTc, a))
-> TcM ((LPat GhcTc, a), Type))
-> (ExpSigmaTypeFRR -> TcM (LPat GhcTc, a))
-> TcM ((LPat GhcTc, a), Type)
forall a b. (a -> b) -> a -> b
$ \ ExpSigmaTypeFRR
exp_ty ->
Scaled ExpSigmaTypeFRR -> Checker (LPat GhcRn) (LPat GhcTc)
tc_lpat (ExpSigmaTypeFRR -> Scaled ExpSigmaTypeFRR
forall a. a -> Scaled a
unrestricted ExpSigmaTypeFRR
exp_ty) PatEnv
penv LPat GhcRn
pat TcM a
thing_inside
where
penv :: PatEnv
penv = PE { pe_lazy :: Bool
pe_lazy = Bool
False, pe_ctxt :: PatCtxt
pe_ctxt = HsMatchContext GhcTc -> PatCtxt
LamPat HsMatchContext GhcTc
ctxt, pe_orig :: CtOrigin
pe_orig = CtOrigin
PatOrigin }
tcCheckPat :: HsMatchContext GhcTc
-> LPat GhcRn -> Scaled TcSigmaTypeFRR
-> TcM a
-> TcM (LPat GhcTc, a)
tcCheckPat :: forall a.
HsMatchContext GhcTc
-> LPat GhcRn -> Scaled Type -> TcM a -> TcM (LPat GhcTc, a)
tcCheckPat HsMatchContext GhcTc
ctxt = HsMatchContext GhcTc
-> CtOrigin
-> LPat GhcRn
-> Scaled Type
-> TcM a
-> TcM (LPat GhcTc, a)
forall a.
HsMatchContext GhcTc
-> CtOrigin
-> LPat GhcRn
-> Scaled Type
-> TcM a
-> TcM (LPat GhcTc, a)
tcCheckPat_O HsMatchContext GhcTc
ctxt CtOrigin
PatOrigin
tcCheckPat_O :: HsMatchContext GhcTc
-> CtOrigin
-> LPat GhcRn -> Scaled TcSigmaTypeFRR
-> TcM a
-> TcM (LPat GhcTc, a)
tcCheckPat_O :: forall a.
HsMatchContext GhcTc
-> CtOrigin
-> LPat GhcRn
-> Scaled Type
-> TcM a
-> TcM (LPat GhcTc, a)
tcCheckPat_O HsMatchContext GhcTc
ctxt CtOrigin
orig LPat GhcRn
pat (Scaled Type
pat_mult Type
pat_ty) TcM a
thing_inside
= Scaled ExpSigmaTypeFRR -> Checker (LPat GhcRn) (LPat GhcTc)
tc_lpat (Type -> ExpSigmaTypeFRR -> Scaled ExpSigmaTypeFRR
forall a. Type -> a -> Scaled a
Scaled Type
pat_mult (Type -> ExpSigmaTypeFRR
mkCheckExpType Type
pat_ty)) PatEnv
penv LPat GhcRn
pat TcM a
thing_inside
where
penv :: PatEnv
penv = PE { pe_lazy :: Bool
pe_lazy = Bool
False, pe_ctxt :: PatCtxt
pe_ctxt = HsMatchContext GhcTc -> PatCtxt
LamPat HsMatchContext GhcTc
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 GhcTc)
| LetPat
{ PatCtxt -> TcLevel
pc_lvl :: TcLevel
, PatCtxt -> Name -> Maybe TyCoVar
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
forall doc. IsLine doc => String -> doc
text String
"LetLclBndr"
ppr (LetGblBndr {}) = String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"LetGblBndr"
makeLazy :: PatEnv -> PatEnv
makeLazy :: PatEnv -> PatEnv
makeLazy PatEnv
penv = PatEnv
penv { pe_lazy = 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 ExpSigmaTypeFRR -> TcM (HsWrapper, TcId)
tcPatBndr :: PatEnv
-> Name -> Scaled ExpSigmaTypeFRR -> TcM (HsWrapper, TyCoVar)
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 TyCoVar
pc_sig_fn = Name -> Maybe TyCoVar
sig_fn
, pc_new :: PatCtxt -> LetBndrSpec
pc_new = LetBndrSpec
no_gen } })
Name
bndr_name Scaled ExpSigmaTypeFRR
exp_pat_ty
| Just TyCoVar
bndr_id <- Name -> Maybe TyCoVar
sig_fn Name
bndr_name
= do { HsWrapper
wrap <- PatEnv -> ExpSigmaTypeFRR -> Type -> TcM HsWrapper
tc_sub_type PatEnv
penv (Scaled ExpSigmaTypeFRR -> ExpSigmaTypeFRR
forall a. Scaled a -> a
scaledThing Scaled ExpSigmaTypeFRR
exp_pat_ty) (TyCoVar -> Type
idType TyCoVar
bndr_id)
; String -> SDoc -> TcRn ()
traceTc String
"tcPatBndr(sig)" (TyCoVar -> SDoc
forall a. Outputable a => a -> SDoc
ppr TyCoVar
bndr_id SDoc -> SDoc -> SDoc
forall doc. IsDoc doc => doc -> doc -> doc
$$ Type -> SDoc
forall a. Outputable a => a -> SDoc
ppr (TyCoVar -> Type
idType TyCoVar
bndr_id) SDoc -> SDoc -> SDoc
forall doc. IsDoc doc => doc -> doc -> doc
$$ Scaled ExpSigmaTypeFRR -> SDoc
forall a. Outputable a => a -> SDoc
ppr Scaled ExpSigmaTypeFRR
exp_pat_ty)
; (HsWrapper, TyCoVar) -> TcM (HsWrapper, TyCoVar)
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return (HsWrapper
wrap, TyCoVar
bndr_id) }
| Bool
otherwise
= do { (TcCoercionN
co, Type
bndr_ty) <- case Scaled ExpSigmaTypeFRR -> ExpSigmaTypeFRR
forall a. Scaled a -> a
scaledThing Scaled ExpSigmaTypeFRR
exp_pat_ty of
Check Type
pat_ty -> TcLevel
-> Type -> IOEnv (Env TcGblEnv TcLclEnv) (TcCoercionN, Type)
promoteTcType TcLevel
bind_lvl Type
pat_ty
Infer InferResult
infer_res -> Bool
-> IOEnv (Env TcGblEnv TcLclEnv) (TcCoercionN, Type)
-> IOEnv (Env TcGblEnv TcLclEnv) (TcCoercionN, Type)
forall a. HasCallStack => Bool -> a -> a
assert (TcLevel
bind_lvl TcLevel -> TcLevel -> Bool
forall a. Eq a => a -> a -> Bool
== InferResult -> TcLevel
ir_lvl InferResult
infer_res) (IOEnv (Env TcGblEnv TcLclEnv) (TcCoercionN, Type)
-> IOEnv (Env TcGblEnv TcLclEnv) (TcCoercionN, Type))
-> IOEnv (Env TcGblEnv TcLclEnv) (TcCoercionN, Type)
-> IOEnv (Env TcGblEnv TcLclEnv) (TcCoercionN, Type)
forall a b. (a -> b) -> a -> b
$
do { Type
bndr_ty <- InferResult -> TcM Type
inferResultToType InferResult
infer_res
; (TcCoercionN, Type)
-> IOEnv (Env TcGblEnv TcLclEnv) (TcCoercionN, Type)
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return (Type -> TcCoercionN
mkNomReflCo Type
bndr_ty, Type
bndr_ty) }
; let bndr_mult :: Type
bndr_mult = Scaled ExpSigmaTypeFRR -> Type
forall a. Scaled a -> Type
scaledMult Scaled ExpSigmaTypeFRR
exp_pat_ty
; TyCoVar
bndr_id <- LetBndrSpec -> Name -> Type -> Type -> TcM TyCoVar
newLetBndr LetBndrSpec
no_gen Name
bndr_name Type
bndr_mult Type
bndr_ty
; String -> SDoc -> TcRn ()
traceTc String
"tcPatBndr(nosig)" ([SDoc] -> SDoc
forall doc. IsDoc doc => [doc] -> doc
vcat [ TcLevel -> SDoc
forall a. Outputable a => a -> SDoc
ppr TcLevel
bind_lvl
, Scaled ExpSigmaTypeFRR -> SDoc
forall a. Outputable a => a -> SDoc
ppr Scaled ExpSigmaTypeFRR
exp_pat_ty, Type -> SDoc
forall a. Outputable a => a -> SDoc
ppr Type
bndr_ty, TcCoercionN -> SDoc
forall a. Outputable a => a -> SDoc
ppr TcCoercionN
co
, TyCoVar -> SDoc
forall a. Outputable a => a -> SDoc
ppr TyCoVar
bndr_id ])
; (HsWrapper, TyCoVar) -> TcM (HsWrapper, TyCoVar)
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return (TcCoercionN -> HsWrapper
mkWpCastN TcCoercionN
co, TyCoVar
bndr_id) }
tcPatBndr PatEnv
_ Name
bndr_name Scaled ExpSigmaTypeFRR
pat_ty
= do { let pat_mult :: Type
pat_mult = Scaled ExpSigmaTypeFRR -> Type
forall a. Scaled a -> Type
scaledMult Scaled ExpSigmaTypeFRR
pat_ty
; Type
pat_ty <- ExpSigmaTypeFRR -> TcM Type
expTypeToType (Scaled ExpSigmaTypeFRR -> ExpSigmaTypeFRR
forall a. Scaled a -> a
scaledThing Scaled ExpSigmaTypeFRR
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
forall doc. IsDoc doc => doc -> doc -> doc
$$ Type -> SDoc
forall a. Outputable a => a -> SDoc
ppr Type
pat_ty)
; (HsWrapper, TyCoVar) -> TcM (HsWrapper, TyCoVar)
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return (HsWrapper
idHsWrapper, HasDebugCallStack => Name -> Type -> Type -> TyCoVar
Name -> Type -> Type -> TyCoVar
mkLocalIdOrCoVar Name
bndr_name Type
pat_mult Type
pat_ty) }
newLetBndr :: LetBndrSpec -> Name -> Mult -> TcType -> TcM TcId
newLetBndr :: LetBndrSpec -> Name -> Type -> Type -> TcM TyCoVar
newLetBndr LetBndrSpec
LetLclBndr Name
name Type
w Type
ty
= do { Name
mono_name <- Name -> TcM Name
cloneLocalName Name
name
; TyCoVar -> TcM TyCoVar
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return (HasDebugCallStack => Name -> Type -> Type -> TyCoVar
Name -> Type -> Type -> TyCoVar
mkLocalId Name
mono_name Type
w Type
ty) }
newLetBndr (LetGblBndr TcPragEnv
prags) Name
name Type
w Type
ty
= TyCoVar -> [LSig GhcRn] -> TcM TyCoVar
addInlinePrags (HasDebugCallStack => Name -> Type -> Type -> TyCoVar
Name -> Type -> Type -> TyCoVar
mkLocalId Name
name Type
w Type
ty) (TcPragEnv -> Name -> [LSig GhcRn]
lookupPragEnv TcPragEnv
prags Name
name)
tc_sub_type :: PatEnv -> ExpSigmaType -> TcSigmaType -> TcM HsWrapper
tc_sub_type :: PatEnv -> ExpSigmaTypeFRR -> Type -> TcM HsWrapper
tc_sub_type PatEnv
penv ExpSigmaTypeFRR
t1 Type
t2 = CtOrigin
-> UserTypeCtxt -> ExpSigmaTypeFRR -> Type -> TcM HsWrapper
tcSubTypePat (PatEnv -> CtOrigin
pe_orig PatEnv
penv) UserTypeCtxt
GenSigCtxt ExpSigmaTypeFRR
t1 Type
t2
type Checker inp out = forall r.
PatEnv
-> inp
-> TcM r
-> TcM ( out
, r
)
tcMultiple_ :: Checker inp () -> PatEnv -> [inp] -> TcM r -> TcM r
tcMultiple_ :: forall inp r. Checker inp () -> PatEnv -> [inp] -> TcM r -> TcM r
tcMultiple_ Checker inp ()
tc_pat PatEnv
penv [inp]
args TcM r
thing_inside
= do { ([()]
_, r
res) <- Checker inp () -> Checker [inp] [()]
forall inp out. Checker inp out -> Checker [inp] [out]
tcMultiple PatEnv -> inp -> TcM r -> TcM ((), r)
Checker inp ()
tc_pat PatEnv
penv [inp]
args TcM r
thing_inside
; r -> TcM r
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return r
res }
tcMultiple :: Checker inp out -> Checker [inp] [out]
tcMultiple :: forall inp out. 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 a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
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 a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
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 ExpSigmaTypeFRR
-> Checker (LPat GhcRn) (LPat GhcTc)
tc_lpat :: Scaled ExpSigmaTypeFRR -> Checker (LPat GhcRn) (LPat GhcTc)
tc_lpat Scaled ExpSigmaTypeFRR
pat_ty PatEnv
penv (L SrcSpanAnnA
span Pat GhcRn
pat) TcM r
thing_inside
= SrcSpanAnnA -> TcRn (LPat GhcTc, r) -> TcRn (LPat GhcTc, r)
forall ann a. SrcSpanAnn' ann -> TcRn a -> TcRn a
setSrcSpanA SrcSpanAnnA
span (TcRn (LPat GhcTc, r) -> TcRn (LPat GhcTc, r))
-> TcRn (LPat GhcTc, r) -> TcRn (LPat 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 ExpSigmaTypeFRR -> Checker (Pat GhcRn) (Pat GhcTc)
tc_pat Scaled ExpSigmaTypeFRR
pat_ty PatEnv
penv Pat GhcRn
pat)
TcM r
thing_inside
; (GenLocated SrcSpanAnnA (Pat GhcTc), r)
-> IOEnv
(Env TcGblEnv TcLclEnv) (GenLocated SrcSpanAnnA (Pat GhcTc), r)
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
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 ExpSigmaTypeFRR]
-> Checker [LPat GhcRn] [LPat GhcTc]
tc_lpats :: [Scaled ExpSigmaTypeFRR] -> Checker [LPat GhcRn] [LPat GhcTc]
tc_lpats [Scaled ExpSigmaTypeFRR]
tys PatEnv
penv [LPat GhcRn]
pats
= Bool
-> SDoc
-> (TcM r -> TcM ([LPat GhcTc], r))
-> TcM r
-> TcM ([LPat GhcTc], r)
forall a. HasCallStack => Bool -> SDoc -> a -> a
assertPpr ([GenLocated SrcSpanAnnA (Pat GhcRn)]
-> [Scaled ExpSigmaTypeFRR] -> Bool
forall a b. [a] -> [b] -> Bool
equalLength [LPat GhcRn]
[GenLocated SrcSpanAnnA (Pat GhcRn)]
pats [Scaled ExpSigmaTypeFRR]
tys) ([GenLocated SrcSpanAnnA (Pat GhcRn)] -> SDoc
forall a. Outputable a => a -> SDoc
ppr [LPat GhcRn]
[GenLocated SrcSpanAnnA (Pat GhcRn)]
pats SDoc -> SDoc -> SDoc
forall doc. IsDoc doc => doc -> doc -> doc
$$ [Scaled ExpSigmaTypeFRR] -> SDoc
forall a. Outputable a => a -> SDoc
ppr [Scaled ExpSigmaTypeFRR]
tys) ((TcM r -> TcM ([LPat GhcTc], r))
-> TcM r -> TcM ([LPat GhcTc], r))
-> (TcM r -> TcM ([LPat GhcTc], r))
-> TcM r
-> TcM ([LPat GhcTc], r)
forall a b. (a -> b) -> a -> b
$
Checker
(GenLocated SrcSpanAnnA (Pat GhcRn), Scaled ExpSigmaTypeFRR)
(GenLocated SrcSpanAnnA (Pat GhcTc))
-> Checker
[(GenLocated SrcSpanAnnA (Pat GhcRn), Scaled ExpSigmaTypeFRR)]
[GenLocated SrcSpanAnnA (Pat GhcTc)]
forall inp out. Checker inp out -> Checker [inp] [out]
tcMultiple (\ PatEnv
penv' (GenLocated SrcSpanAnnA (Pat GhcRn)
p,Scaled ExpSigmaTypeFRR
t) -> Scaled ExpSigmaTypeFRR -> Checker (LPat GhcRn) (LPat GhcTc)
tc_lpat Scaled ExpSigmaTypeFRR
t PatEnv
penv' LPat GhcRn
GenLocated SrcSpanAnnA (Pat GhcRn)
p)
PatEnv
penv
(String
-> [GenLocated SrcSpanAnnA (Pat GhcRn)]
-> [Scaled ExpSigmaTypeFRR]
-> [(GenLocated SrcSpanAnnA (Pat GhcRn), Scaled ExpSigmaTypeFRR)]
forall a b. HasDebugCallStack => String -> [a] -> [b] -> [(a, b)]
zipEqual String
"tc_lpats" [LPat GhcRn]
[GenLocated SrcSpanAnnA (Pat GhcRn)]
pats [Scaled ExpSigmaTypeFRR]
tys)
checkManyPattern :: Scaled a -> TcM HsWrapper
checkManyPattern :: forall a. Scaled a -> TcM HsWrapper
checkManyPattern Scaled a
pat_ty = CtOrigin -> Type -> Type -> TcM HsWrapper
tcSubMult CtOrigin
NonLinearPatternOrigin Type
ManyTy (Scaled a -> Type
forall a. Scaled a -> Type
scaledMult Scaled a
pat_ty)
tc_pat :: Scaled ExpSigmaTypeFRR
-> Checker (Pat GhcRn) (Pat GhcTc)
tc_pat :: Scaled ExpSigmaTypeFRR -> Checker (Pat GhcRn) (Pat GhcTc)
tc_pat Scaled ExpSigmaTypeFRR
pat_ty PatEnv
penv Pat GhcRn
ps_pat TcM r
thing_inside = case Pat GhcRn
ps_pat of
VarPat XVarPat GhcRn
x (L SrcSpanAnnN
l Name
name) -> do
{ (HsWrapper
wrap, TyCoVar
id) <- PatEnv
-> Name -> Scaled ExpSigmaTypeFRR -> TcM (HsWrapper, TyCoVar)
tcPatBndr PatEnv
penv Name
name Scaled ExpSigmaTypeFRR
pat_ty
; (r
res, HsWrapper
mult_wrap) <- Name -> Type -> TcM r -> TcM (r, HsWrapper)
forall a. Name -> Type -> TcM a -> TcM (a, HsWrapper)
tcCheckUsage Name
name (Scaled ExpSigmaTypeFRR -> Type
forall a. Scaled a -> Type
scaledMult Scaled ExpSigmaTypeFRR
pat_ty) (TcM r -> TcM (r, HsWrapper)) -> TcM r -> TcM (r, HsWrapper)
forall a b. (a -> b) -> a -> b
$
Name -> TyCoVar -> TcM r -> TcM r
forall a. Name -> TyCoVar -> TcM a -> TcM a
tcExtendIdEnv1 Name
name TyCoVar
id TcM r
thing_inside
; Type
pat_ty <- ExpSigmaTypeFRR -> TcM Type
forall (m :: * -> *). MonadIO m => ExpSigmaTypeFRR -> m Type
readExpType (Scaled ExpSigmaTypeFRR -> ExpSigmaTypeFRR
forall a. Scaled a -> a
scaledThing Scaled ExpSigmaTypeFRR
pat_ty)
; (Pat GhcTc, r) -> TcM (Pat GhcTc, r)
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return (HsWrapper -> Pat GhcTc -> Type -> 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 -> TyCoVar -> GenLocated SrcSpanAnnN TyCoVar
forall l e. l -> e -> GenLocated l e
L SrcSpanAnnN
l TyCoVar
id)) Type
pat_ty, r
res) }
ParPat XParPat GhcRn
x LHsToken "(" GhcRn
lpar LPat GhcRn
pat LHsToken ")" GhcRn
rpar -> do
{ (GenLocated SrcSpanAnnA (Pat GhcTc)
pat', r
res) <- Scaled ExpSigmaTypeFRR -> Checker (LPat GhcRn) (LPat GhcTc)
tc_lpat Scaled ExpSigmaTypeFRR
pat_ty PatEnv
penv LPat GhcRn
pat TcM r
thing_inside
; (Pat GhcTc, r) -> TcM (Pat GhcTc, r)
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return (XParPat GhcTc
-> LHsToken "(" GhcTc
-> LPat GhcTc
-> LHsToken ")" GhcTc
-> Pat GhcTc
forall p.
XParPat p -> LHsToken "(" p -> LPat p -> LHsToken ")" p -> Pat p
ParPat XParPat GhcRn
XParPat GhcTc
x LHsToken "(" GhcRn
LHsToken "(" GhcTc
lpar LPat GhcTc
GenLocated SrcSpanAnnA (Pat GhcTc)
pat' LHsToken ")" GhcRn
LHsToken ")" GhcTc
rpar, r
res) }
BangPat XBangPat GhcRn
x LPat GhcRn
pat -> do
{ (GenLocated SrcSpanAnnA (Pat GhcTc)
pat', r
res) <- Scaled ExpSigmaTypeFRR -> Checker (LPat GhcRn) (LPat GhcTc)
tc_lpat Scaled ExpSigmaTypeFRR
pat_ty PatEnv
penv LPat GhcRn
pat TcM r
thing_inside
; (Pat GhcTc, r) -> TcM (Pat GhcTc, r)
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
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 LPat GhcTc
GenLocated SrcSpanAnnA (Pat GhcTc)
pat', r
res) }
LazyPat XLazyPat GhcRn
x LPat GhcRn
pat -> do
{ HsWrapper
mult_wrap <- Scaled ExpSigmaTypeFRR -> TcM HsWrapper
forall a. Scaled a -> TcM HsWrapper
checkManyPattern Scaled ExpSigmaTypeFRR
pat_ty
; (GenLocated SrcSpanAnnA (Pat GhcTc)
pat', (r
res, WantedConstraints
pat_ct))
<- Scaled ExpSigmaTypeFRR -> Checker (LPat GhcRn) (LPat GhcTc)
tc_lpat Scaled ExpSigmaTypeFRR
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
; Type
pat_ty <- ExpSigmaTypeFRR -> TcM Type
forall (m :: * -> *). MonadIO m => ExpSigmaTypeFRR -> m Type
readExpType (Scaled ExpSigmaTypeFRR -> ExpSigmaTypeFRR
forall a. Scaled a -> a
scaledThing Scaled ExpSigmaTypeFRR
pat_ty)
; TcCoercionN
_ <- Maybe TypedThing -> Type -> Type -> TcM TcCoercionN
unifyType Maybe TypedThing
forall a. Maybe a
Nothing (HasDebugCallStack => Type -> Type
Type -> Type
typeKind Type
pat_ty) Type
liftedTypeKind
; (Pat GhcTc, r) -> TcM (Pat GhcTc, r)
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return (HsWrapper -> Pat GhcTc -> Type -> 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 LPat GhcTc
GenLocated SrcSpanAnnA (Pat GhcTc)
pat') Type
pat_ty, r
res) }
WildPat XWildPat GhcRn
_ -> do
{ HsWrapper
mult_wrap <- Scaled ExpSigmaTypeFRR -> TcM HsWrapper
forall a. Scaled a -> TcM HsWrapper
checkManyPattern Scaled ExpSigmaTypeFRR
pat_ty
; r
res <- TcM r
thing_inside
; Type
pat_ty <- ExpSigmaTypeFRR -> TcM Type
expTypeToType (Scaled ExpSigmaTypeFRR -> ExpSigmaTypeFRR
forall a. Scaled a -> a
scaledThing Scaled ExpSigmaTypeFRR
pat_ty)
; (Pat GhcTc, r) -> TcM (Pat GhcTc, r)
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return (HsWrapper -> Pat GhcTc -> Type -> Pat GhcTc
mkHsWrapPat HsWrapper
mult_wrap (XWildPat GhcTc -> Pat GhcTc
forall p. XWildPat p -> Pat p
WildPat XWildPat GhcTc
Type
pat_ty) Type
pat_ty, r
res) }
AsPat XAsPat GhcRn
x (L SrcSpanAnnN
nm_loc Name
name) LHsToken "@" GhcRn
at LPat GhcRn
pat -> do
{ HsWrapper
mult_wrap <- Scaled ExpSigmaTypeFRR -> TcM HsWrapper
forall a. Scaled a -> TcM HsWrapper
checkManyPattern Scaled ExpSigmaTypeFRR
pat_ty
; (HsWrapper
wrap, TyCoVar
bndr_id) <- SrcSpanAnnN -> TcM (HsWrapper, TyCoVar) -> TcM (HsWrapper, TyCoVar)
forall ann a. SrcSpanAnn' ann -> TcRn a -> TcRn a
setSrcSpanA SrcSpanAnnN
nm_loc (PatEnv
-> Name -> Scaled ExpSigmaTypeFRR -> TcM (HsWrapper, TyCoVar)
tcPatBndr PatEnv
penv Name
name Scaled ExpSigmaTypeFRR
pat_ty)
; (GenLocated SrcSpanAnnA (Pat GhcTc)
pat', r
res) <- Name
-> TyCoVar
-> IOEnv
(Env TcGblEnv TcLclEnv) (GenLocated SrcSpanAnnA (Pat GhcTc), r)
-> IOEnv
(Env TcGblEnv TcLclEnv) (GenLocated SrcSpanAnnA (Pat GhcTc), r)
forall a. Name -> TyCoVar -> TcM a -> TcM a
tcExtendIdEnv1 Name
name TyCoVar
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 ExpSigmaTypeFRR -> Checker (LPat GhcRn) (LPat GhcTc)
tc_lpat (Scaled ExpSigmaTypeFRR
pat_ty Scaled ExpSigmaTypeFRR -> ExpSigmaTypeFRR -> Scaled ExpSigmaTypeFRR
forall a b. Scaled a -> b -> Scaled b
`scaledSet`(Type -> ExpSigmaTypeFRR
mkCheckExpType (Type -> ExpSigmaTypeFRR) -> Type -> ExpSigmaTypeFRR
forall a b. (a -> b) -> a -> b
$ TyCoVar -> Type
idType TyCoVar
bndr_id))
PatEnv
penv LPat GhcRn
pat TcM r
thing_inside
; Type
pat_ty <- ExpSigmaTypeFRR -> TcM Type
forall (m :: * -> *). MonadIO m => ExpSigmaTypeFRR -> m Type
readExpType (Scaled ExpSigmaTypeFRR -> ExpSigmaTypeFRR
forall a. Scaled a -> a
scaledThing Scaled ExpSigmaTypeFRR
pat_ty)
; (Pat GhcTc, r) -> TcM (Pat GhcTc, r)
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return (HsWrapper -> Pat GhcTc -> Type -> Pat GhcTc
mkHsWrapPat (HsWrapper
wrap HsWrapper -> HsWrapper -> HsWrapper
<.> HsWrapper
mult_wrap) (XAsPat GhcTc
-> LIdP GhcTc -> LHsToken "@" GhcTc -> LPat GhcTc -> Pat GhcTc
forall p. XAsPat p -> LIdP p -> LHsToken "@" p -> LPat p -> Pat p
AsPat XAsPat GhcRn
XAsPat GhcTc
x (SrcSpanAnnN -> TyCoVar -> GenLocated SrcSpanAnnN TyCoVar
forall l e. l -> e -> GenLocated l e
L SrcSpanAnnN
nm_loc TyCoVar
bndr_id) LHsToken "@" GhcRn
LHsToken "@" GhcTc
at LPat GhcTc
GenLocated SrcSpanAnnA (Pat GhcTc)
pat') Type
pat_ty, r
res) }
ViewPat XViewPat GhcRn
_ LHsExpr GhcRn
expr LPat GhcRn
pat -> do
{ HsWrapper
mult_wrap <- Scaled ExpSigmaTypeFRR -> TcM HsWrapper
forall a. Scaled a -> TcM HsWrapper
checkManyPattern Scaled ExpSigmaTypeFRR
pat_ty
; (GenLocated SrcSpanAnnA (HsExpr GhcTc)
expr',Type
expr_ty) <- LHsExpr GhcRn -> TcM (LHsExpr GhcTc, Type)
tcInferRho LHsExpr GhcRn
expr
; let herald :: ExpectedFunTyOrigin
herald = HsExpr GhcRn -> ExpectedFunTyOrigin
ExpectedFunTyViewPat (HsExpr GhcRn -> ExpectedFunTyOrigin)
-> HsExpr GhcRn -> ExpectedFunTyOrigin
forall a b. (a -> b) -> a -> b
$ GenLocated SrcSpanAnnA (HsExpr GhcRn) -> HsExpr GhcRn
forall l e. GenLocated l e -> e
unLoc LHsExpr GhcRn
GenLocated SrcSpanAnnA (HsExpr GhcRn)
expr
; (HsWrapper
expr_wrap1, Scaled Type
_mult Type
inf_arg_ty, Type
inf_res_sigma)
<- ExpectedFunTyOrigin
-> Maybe TypedThing
-> (Int, [Scaled Type])
-> Type
-> TcM (HsWrapper, Scaled Type, Type)
matchActualFunTySigma ExpectedFunTyOrigin
herald (TypedThing -> Maybe TypedThing
forall a. a -> Maybe a
Just (TypedThing -> Maybe TypedThing)
-> (HsExpr GhcRn -> TypedThing) -> HsExpr GhcRn -> Maybe TypedThing
forall b c a. (b -> c) -> (a -> b) -> a -> c
. HsExpr GhcRn -> TypedThing
HsExprRnThing (HsExpr GhcRn -> Maybe TypedThing)
-> HsExpr GhcRn -> Maybe TypedThing
forall a b. (a -> b) -> a -> b
$ GenLocated SrcSpanAnnA (HsExpr GhcRn) -> HsExpr GhcRn
forall l e. GenLocated l e -> e
unLoc LHsExpr GhcRn
GenLocated SrcSpanAnnA (HsExpr GhcRn)
expr) (Int
1,[]) Type
expr_ty
; HsWrapper
expr_wrap2 <- PatEnv -> ExpSigmaTypeFRR -> Type -> TcM HsWrapper
tc_sub_type PatEnv
penv (Scaled ExpSigmaTypeFRR -> ExpSigmaTypeFRR
forall a. Scaled a -> a
scaledThing Scaled ExpSigmaTypeFRR
pat_ty) Type
inf_arg_ty
; (GenLocated SrcSpanAnnA (Pat GhcTc)
pat', r
res) <- Scaled ExpSigmaTypeFRR -> Checker (LPat GhcRn) (LPat GhcTc)
tc_lpat (Scaled ExpSigmaTypeFRR
pat_ty Scaled ExpSigmaTypeFRR -> ExpSigmaTypeFRR -> Scaled ExpSigmaTypeFRR
forall a b. Scaled a -> b -> Scaled b
`scaledSet` Type -> ExpSigmaTypeFRR
mkCheckExpType Type
inf_res_sigma) PatEnv
penv LPat GhcRn
pat TcM r
thing_inside
; let Scaled Type
w ExpSigmaTypeFRR
h_pat_ty = Scaled ExpSigmaTypeFRR
pat_ty
; Type
pat_ty <- ExpSigmaTypeFRR -> TcM Type
forall (m :: * -> *). MonadIO m => ExpSigmaTypeFRR -> m Type
readExpType ExpSigmaTypeFRR
h_pat_ty
; let expr_wrap2' :: HsWrapper
expr_wrap2' = HsWrapper -> HsWrapper -> Scaled Type -> Type -> HsWrapper
mkWpFun HsWrapper
expr_wrap2 HsWrapper
idHsWrapper
(Type -> Type -> Scaled Type
forall a. Type -> a -> Scaled a
Scaled Type
w Type
pat_ty) Type
inf_res_sigma
; let
expr_wrap :: HsWrapper
expr_wrap = HsWrapper
expr_wrap2' HsWrapper -> HsWrapper -> HsWrapper
<.> HsWrapper
expr_wrap1 HsWrapper -> HsWrapper -> HsWrapper
<.> HsWrapper
mult_wrap
; (Pat GhcTc, r) -> TcM (Pat GhcTc, r)
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return ((Pat GhcTc, r) -> TcM (Pat GhcTc, r))
-> (Pat GhcTc, r) -> TcM (Pat GhcTc, r)
forall a b. (a -> b) -> a -> b
$ (XViewPat GhcTc -> LHsExpr GhcTc -> LPat GhcTc -> Pat GhcTc
forall p. XViewPat p -> LHsExpr p -> LPat p -> Pat p
ViewPat XViewPat GhcTc
Type
pat_ty (HsWrapper -> LHsExpr GhcTc -> LHsExpr GhcTc
mkLHsWrap HsWrapper
expr_wrap LHsExpr GhcTc
GenLocated SrcSpanAnnA (HsExpr GhcTc)
expr') LPat GhcTc
GenLocated SrcSpanAnnA (Pat GhcTc)
pat', r
res) }
SigPat XSigPat GhcRn
_ LPat GhcRn
pat HsPatSigType (NoGhcTc GhcRn)
sig_ty -> do
{ (Type
inner_ty, [(Name, TyCoVar)]
tv_binds, [(Name, TyCoVar)]
wcs, HsWrapper
wrap) <- Bool
-> HsPatSigType GhcRn
-> ExpSigmaTypeFRR
-> TcM (Type, [(Name, TyCoVar)], [(Name, TyCoVar)], HsWrapper)
tcPatSig (PatEnv -> Bool
inPatBind PatEnv
penv)
HsPatSigType (NoGhcTc GhcRn)
HsPatSigType GhcRn
sig_ty (Scaled ExpSigmaTypeFRR -> ExpSigmaTypeFRR
forall a. Scaled a -> a
scaledThing Scaled ExpSigmaTypeFRR
pat_ty)
; (GenLocated SrcSpanAnnA (Pat GhcTc)
pat', r
res) <- [(Name, TyCoVar)]
-> IOEnv
(Env TcGblEnv TcLclEnv) (GenLocated SrcSpanAnnA (Pat GhcTc), r)
-> IOEnv
(Env TcGblEnv TcLclEnv) (GenLocated SrcSpanAnnA (Pat GhcTc), r)
forall r. [(Name, TyCoVar)] -> TcM r -> TcM r
tcExtendNameTyVarEnv [(Name, TyCoVar)]
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, TyCoVar)]
-> IOEnv
(Env TcGblEnv TcLclEnv) (GenLocated SrcSpanAnnA (Pat GhcTc), r)
-> IOEnv
(Env TcGblEnv TcLclEnv) (GenLocated SrcSpanAnnA (Pat GhcTc), r)
forall r. [(Name, TyCoVar)] -> TcM r -> TcM r
tcExtendNameTyVarEnv [(Name, TyCoVar)]
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 ExpSigmaTypeFRR -> Checker (LPat GhcRn) (LPat GhcTc)
tc_lpat (Scaled ExpSigmaTypeFRR
pat_ty Scaled ExpSigmaTypeFRR -> ExpSigmaTypeFRR -> Scaled ExpSigmaTypeFRR
forall a b. Scaled a -> b -> Scaled b
`scaledSet` Type -> ExpSigmaTypeFRR
mkCheckExpType Type
inner_ty) PatEnv
penv LPat GhcRn
pat TcM r
thing_inside
; Type
pat_ty <- ExpSigmaTypeFRR -> TcM Type
forall (m :: * -> *). MonadIO m => ExpSigmaTypeFRR -> m Type
readExpType (Scaled ExpSigmaTypeFRR -> ExpSigmaTypeFRR
forall a. Scaled a -> a
scaledThing Scaled ExpSigmaTypeFRR
pat_ty)
; (Pat GhcTc, r) -> TcM (Pat GhcTc, r)
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return (HsWrapper -> Pat GhcTc -> Type -> 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 XSigPat GhcTc
Type
inner_ty LPat GhcTc
GenLocated SrcSpanAnnA (Pat GhcTc)
pat' HsPatSigType (NoGhcTc GhcRn)
HsPatSigType (NoGhcTc GhcTc)
sig_ty) Type
pat_ty, r
res) }
ListPat XListPat GhcRn
_ [LPat GhcRn]
pats -> do
{ (HsWrapper
coi, Type
elt_ty) <- (Type -> IOEnv (Env TcGblEnv TcLclEnv) (TcCoercionN, Type))
-> PatEnv -> ExpSigmaTypeFRR -> TcM (HsWrapper, Type)
forall a.
(Type -> TcM (TcCoercionN, a))
-> PatEnv -> ExpSigmaTypeFRR -> TcM (HsWrapper, a)
matchExpectedPatTy Type -> IOEnv (Env TcGblEnv TcLclEnv) (TcCoercionN, Type)
matchExpectedListTy PatEnv
penv (Scaled ExpSigmaTypeFRR -> ExpSigmaTypeFRR
forall a. Scaled a -> a
scaledThing Scaled ExpSigmaTypeFRR
pat_ty)
; ([GenLocated SrcSpanAnnA (Pat GhcTc)]
pats', r
res) <- Checker
(GenLocated SrcSpanAnnA (Pat GhcRn))
(GenLocated SrcSpanAnnA (Pat GhcTc))
-> Checker
[GenLocated SrcSpanAnnA (Pat GhcRn)]
[GenLocated SrcSpanAnnA (Pat GhcTc)]
forall inp out. Checker inp out -> Checker [inp] [out]
tcMultiple (Scaled ExpSigmaTypeFRR -> Checker (LPat GhcRn) (LPat GhcTc)
tc_lpat (Scaled ExpSigmaTypeFRR
pat_ty Scaled ExpSigmaTypeFRR -> ExpSigmaTypeFRR -> Scaled ExpSigmaTypeFRR
forall a b. Scaled a -> b -> Scaled b
`scaledSet` Type -> ExpSigmaTypeFRR
mkCheckExpType Type
elt_ty))
PatEnv
penv [LPat GhcRn]
[GenLocated SrcSpanAnnA (Pat GhcRn)]
pats TcM r
thing_inside
; Type
pat_ty <- ExpSigmaTypeFRR -> TcM Type
forall (m :: * -> *). MonadIO m => ExpSigmaTypeFRR -> m Type
readExpType (Scaled ExpSigmaTypeFRR -> ExpSigmaTypeFRR
forall a. Scaled a -> a
scaledThing Scaled ExpSigmaTypeFRR
pat_ty)
; (Pat GhcTc, r) -> TcM (Pat GhcTc, r)
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return (HsWrapper -> Pat GhcTc -> Type -> Pat GhcTc
mkHsWrapPat HsWrapper
coi
(XListPat GhcTc -> [LPat GhcTc] -> Pat GhcTc
forall p. XListPat p -> [LPat p] -> Pat p
ListPat XListPat GhcTc
Type
elt_ty [LPat GhcTc]
[GenLocated SrcSpanAnnA (Pat GhcTc)]
pats') Type
pat_ty, r
res)
}
TuplePat XTuplePat GhcRn
_ [LPat GhcRn]
pats Boxity
boxity -> do
{ let arity :: Int
arity = [GenLocated SrcSpanAnnA (Pat GhcRn)] -> Int
forall a. [a] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [LPat GhcRn]
[GenLocated SrcSpanAnnA (Pat GhcRn)]
pats
tc :: TyCon
tc = Boxity -> Int -> TyCon
tupleTyCon Boxity
boxity Int
arity
; Int -> TcRn ()
checkTupSize Int
arity
; (HsWrapper
coi, [Type]
arg_tys) <- (Type -> TcM (TcCoercionN, [Type]))
-> PatEnv -> ExpSigmaTypeFRR -> TcM (HsWrapper, [Type])
forall a.
(Type -> TcM (TcCoercionN, a))
-> PatEnv -> ExpSigmaTypeFRR -> TcM (HsWrapper, a)
matchExpectedPatTy (TyCon -> Type -> TcM (TcCoercionN, [Type])
matchExpectedTyConApp TyCon
tc)
PatEnv
penv (Scaled ExpSigmaTypeFRR -> ExpSigmaTypeFRR
forall a. Scaled a -> a
scaledThing Scaled ExpSigmaTypeFRR
pat_ty)
; let con_arg_tys :: [Type]
con_arg_tys = case Boxity
boxity of Boxity
Unboxed -> Int -> [Type] -> [Type]
forall a. Int -> [a] -> [a]
drop Int
arity [Type]
arg_tys
Boxity
Boxed -> [Type]
arg_tys
; ([GenLocated SrcSpanAnnA (Pat GhcTc)]
pats', r
res) <- [Scaled ExpSigmaTypeFRR] -> Checker [LPat GhcRn] [LPat GhcTc]
tc_lpats ((Type -> Scaled ExpSigmaTypeFRR)
-> [Type] -> [Scaled ExpSigmaTypeFRR]
forall a b. (a -> b) -> [a] -> [b]
map (Scaled ExpSigmaTypeFRR -> ExpSigmaTypeFRR -> Scaled ExpSigmaTypeFRR
forall a b. Scaled a -> b -> Scaled b
scaledSet Scaled ExpSigmaTypeFRR
pat_ty (ExpSigmaTypeFRR -> Scaled ExpSigmaTypeFRR)
-> (Type -> ExpSigmaTypeFRR) -> Type -> Scaled ExpSigmaTypeFRR
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Type -> ExpSigmaTypeFRR
mkCheckExpType) [Type]
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 [Type]
XTuplePat GhcTc
con_arg_tys [LPat GhcTc]
[GenLocated SrcSpanAnnA (Pat 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 XLazyPat GhcTc
NoExtField
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
; Type
pat_ty <- ExpSigmaTypeFRR -> TcM Type
forall (m :: * -> *). MonadIO m => ExpSigmaTypeFRR -> m Type
readExpType (Scaled ExpSigmaTypeFRR -> ExpSigmaTypeFRR
forall a. Scaled a -> a
scaledThing Scaled ExpSigmaTypeFRR
pat_ty)
; Bool -> TcRn ()
forall (m :: * -> *). (HasCallStack, Applicative m) => Bool -> m ()
massert ([Type]
con_arg_tys [Type] -> [GenLocated SrcSpanAnnA (Pat GhcRn)] -> Bool
forall a b. [a] -> [b] -> Bool
`equalLength` [LPat GhcRn]
[GenLocated SrcSpanAnnA (Pat GhcRn)]
pats)
; (Pat GhcTc, r) -> TcM (Pat GhcTc, r)
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return (HsWrapper -> Pat GhcTc -> Type -> Pat GhcTc
mkHsWrapPat HsWrapper
coi Pat GhcTc
possibly_mangled_result Type
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, [Type]
arg_tys) <- (Type -> TcM (TcCoercionN, [Type]))
-> PatEnv -> ExpSigmaTypeFRR -> TcM (HsWrapper, [Type])
forall a.
(Type -> TcM (TcCoercionN, a))
-> PatEnv -> ExpSigmaTypeFRR -> TcM (HsWrapper, a)
matchExpectedPatTy (TyCon -> Type -> TcM (TcCoercionN, [Type])
matchExpectedTyConApp TyCon
tc)
PatEnv
penv (Scaled ExpSigmaTypeFRR -> ExpSigmaTypeFRR
forall a. Scaled a -> a
scaledThing Scaled ExpSigmaTypeFRR
pat_ty)
;
let con_arg_tys :: [Type]
con_arg_tys = Int -> [Type] -> [Type]
forall a. Int -> [a] -> [a]
drop Int
arity [Type]
arg_tys
; (GenLocated SrcSpanAnnA (Pat GhcTc)
pat', r
res) <- Scaled ExpSigmaTypeFRR -> Checker (LPat GhcRn) (LPat GhcTc)
tc_lpat (Scaled ExpSigmaTypeFRR
pat_ty Scaled ExpSigmaTypeFRR -> ExpSigmaTypeFRR -> Scaled ExpSigmaTypeFRR
forall a b. Scaled a -> b -> Scaled b
`scaledSet` Type -> ExpSigmaTypeFRR
mkCheckExpType ([Type]
con_arg_tys [Type] -> Int -> Type
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
; Type
pat_ty <- ExpSigmaTypeFRR -> TcM Type
forall (m :: * -> *). MonadIO m => ExpSigmaTypeFRR -> m Type
readExpType (Scaled ExpSigmaTypeFRR -> ExpSigmaTypeFRR
forall a. Scaled a -> a
scaledThing Scaled ExpSigmaTypeFRR
pat_ty)
; (Pat GhcTc, r) -> TcM (Pat GhcTc, r)
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return (HsWrapper -> Pat GhcTc -> Type -> Pat GhcTc
mkHsWrapPat HsWrapper
coi (XSumPat GhcTc -> LPat GhcTc -> Int -> Int -> Pat GhcTc
forall p. XSumPat p -> LPat p -> Int -> Int -> Pat p
SumPat [Type]
XSumPat GhcTc
con_arg_tys LPat GhcTc
GenLocated SrcSpanAnnA (Pat GhcTc)
pat' Int
alt Int
arity) Type
pat_ty
, r
res)
}
ConPat XConPat GhcRn
_ XRec GhcRn (ConLikeP GhcRn)
con HsConPatDetails GhcRn
arg_pats ->
PatEnv
-> GenLocated SrcSpanAnnN Name
-> Scaled ExpSigmaTypeFRR
-> HsConPatDetails GhcRn
-> TcM r
-> TcM (Pat GhcTc, r)
forall a.
PatEnv
-> GenLocated SrcSpanAnnN Name
-> Scaled ExpSigmaTypeFRR
-> HsConPatDetails GhcRn
-> TcM a
-> TcM (Pat GhcTc, a)
tcConPat PatEnv
penv XRec GhcRn (ConLikeP GhcRn)
GenLocated SrcSpanAnnN Name
con Scaled ExpSigmaTypeFRR
pat_ty HsConPatDetails GhcRn
arg_pats TcM r
thing_inside
LitPat XLitPat GhcRn
x HsLit GhcRn
simple_lit -> do
{ let lit_ty :: Type
lit_ty = HsLit GhcRn -> Type
forall (p :: Pass). HsLit (GhcPass p) -> Type
hsLitType HsLit GhcRn
simple_lit
; HsWrapper
wrap <- PatEnv -> ExpSigmaTypeFRR -> Type -> TcM HsWrapper
tc_sub_type PatEnv
penv (Scaled ExpSigmaTypeFRR -> ExpSigmaTypeFRR
forall a. Scaled a -> a
scaledThing Scaled ExpSigmaTypeFRR
pat_ty) Type
lit_ty
; r
res <- TcM r
thing_inside
; Type
pat_ty <- ExpSigmaTypeFRR -> TcM Type
forall (m :: * -> *). MonadIO m => ExpSigmaTypeFRR -> m Type
readExpType (Scaled ExpSigmaTypeFRR -> ExpSigmaTypeFRR
forall a. Scaled a -> a
scaledThing Scaled ExpSigmaTypeFRR
pat_ty)
; (Pat GhcTc, r) -> TcM (Pat GhcTc, r)
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return ( HsWrapper -> Pat GhcTc -> Type -> 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)) Type
pat_ty
, r
res) }
NPat XNPat GhcRn
_ (L SrcAnn NoEpAnns
l HsOverLit GhcRn
over_lit) Maybe (SyntaxExpr GhcRn)
mb_neg SyntaxExpr GhcRn
eq -> do
{ HsWrapper
mult_wrap <- Scaled ExpSigmaTypeFRR -> TcM HsWrapper
forall a. Scaled a -> TcM HsWrapper
checkManyPattern Scaled ExpSigmaTypeFRR
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]
-> ExpSigmaTypeFRR
-> ([Type] -> [Type] -> TcM (HsOverLit GhcTc, Maybe SyntaxExprTc))
-> TcM ((HsOverLit GhcTc, Maybe SyntaxExprTc), SyntaxExprTc)
forall a.
CtOrigin
-> SyntaxExprRn
-> [SyntaxOpType]
-> ExpSigmaTypeFRR
-> ([Type] -> [Type] -> TcM a)
-> TcM (a, SyntaxExprTc)
tcSyntaxOp CtOrigin
orig SyntaxExpr GhcRn
SyntaxExprRn
eq [ExpSigmaTypeFRR -> SyntaxOpType
SynType (Scaled ExpSigmaTypeFRR -> ExpSigmaTypeFRR
forall a. Scaled a -> a
scaledThing Scaled ExpSigmaTypeFRR
pat_ty), SyntaxOpType
SynAny]
(Type -> ExpSigmaTypeFRR
mkCheckExpType Type
boolTy) (([Type] -> [Type] -> TcM (HsOverLit GhcTc, Maybe SyntaxExprTc))
-> TcM ((HsOverLit GhcTc, Maybe SyntaxExprTc), SyntaxExprTc))
-> ([Type] -> [Type] -> TcM (HsOverLit GhcTc, Maybe SyntaxExprTc))
-> TcM ((HsOverLit GhcTc, Maybe SyntaxExprTc), SyntaxExprTc)
forall a b. (a -> b) -> a -> b
$
\ [Type
neg_lit_ty] [Type]
_ ->
let new_over_lit :: Type -> TcM (HsOverLit GhcTc)
new_over_lit Type
lit_ty = HsOverLit GhcRn -> ExpSigmaTypeFRR -> TcM (HsOverLit GhcTc)
newOverloadedLit HsOverLit GhcRn
over_lit
(Type -> ExpSigmaTypeFRR
mkCheckExpType Type
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
<$> Type -> TcM (HsOverLit GhcTc)
new_over_lit Type
neg_lit_ty
Just SyntaxExpr GhcRn
neg ->
(SyntaxExprTc -> Maybe SyntaxExprTc)
-> (HsOverLit GhcTc, SyntaxExprTc)
-> (HsOverLit GhcTc, Maybe SyntaxExprTc)
forall b c d. (b -> c) -> (d, b) -> (d, c)
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]
-> ExpSigmaTypeFRR
-> ([Type] -> [Type] -> TcM (HsOverLit GhcTc))
-> IOEnv (Env TcGblEnv TcLclEnv) (HsOverLit GhcTc, SyntaxExprTc)
forall a.
CtOrigin
-> SyntaxExprRn
-> [SyntaxOpType]
-> ExpSigmaTypeFRR
-> ([Type] -> [Type] -> TcM a)
-> TcM (a, SyntaxExprTc)
tcSyntaxOp CtOrigin
orig SyntaxExpr GhcRn
SyntaxExprRn
neg [SyntaxOpType
SynRho] (Type -> ExpSigmaTypeFRR
mkCheckExpType Type
neg_lit_ty) (([Type] -> [Type] -> TcM (HsOverLit GhcTc))
-> IOEnv (Env TcGblEnv TcLclEnv) (HsOverLit GhcTc, SyntaxExprTc))
-> ([Type] -> [Type] -> TcM (HsOverLit GhcTc))
-> IOEnv (Env TcGblEnv TcLclEnv) (HsOverLit GhcTc, SyntaxExprTc)
forall a b. (a -> b) -> a -> b
$
\ [Type
lit_ty] [Type]
_ -> Type -> TcM (HsOverLit GhcTc)
new_over_lit Type
lit_ty)
; r
res <- TcM r
thing_inside
; Type
pat_ty <- ExpSigmaTypeFRR -> TcM Type
forall (m :: * -> *). MonadIO m => ExpSigmaTypeFRR -> m Type
readExpType (Scaled ExpSigmaTypeFRR -> ExpSigmaTypeFRR
forall a. Scaled a -> a
scaledThing Scaled ExpSigmaTypeFRR
pat_ty)
; (Pat GhcTc, r) -> TcM (Pat GhcTc, r)
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return (HsWrapper -> Pat GhcTc -> Type -> 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 XNPat GhcTc
Type
pat_ty (SrcAnn NoEpAnns
-> HsOverLit GhcTc
-> GenLocated (SrcAnn NoEpAnns) (HsOverLit GhcTc)
forall l e. l -> e -> GenLocated l e
L SrcAnn NoEpAnns
l HsOverLit GhcTc
lit') Maybe (SyntaxExpr GhcTc)
Maybe SyntaxExprTc
mb_neg' SyntaxExpr GhcTc
SyntaxExprTc
eq') Type
pat_ty, r
res) }
NPlusKPat XNPlusKPat GhcRn
_ (L SrcSpanAnnN
nm_loc Name
name)
(L SrcAnn NoEpAnns
loc HsOverLit GhcRn
lit) HsOverLit GhcRn
_ SyntaxExpr GhcRn
ge SyntaxExpr GhcRn
minus -> do
{ HsWrapper
mult_wrap <- Scaled ExpSigmaTypeFRR -> TcM HsWrapper
forall a. Scaled a -> TcM HsWrapper
checkManyPattern Scaled ExpSigmaTypeFRR
pat_ty
; let pat_exp_ty :: ExpSigmaTypeFRR
pat_exp_ty = Scaled ExpSigmaTypeFRR -> ExpSigmaTypeFRR
forall a. Scaled a -> a
scaledThing Scaled ExpSigmaTypeFRR
pat_ty
orig :: CtOrigin
orig = HsOverLit GhcRn -> CtOrigin
LiteralOrigin HsOverLit GhcRn
lit
; (HsOverLit GhcTc
lit1', SyntaxExprTc
ge')
<- CtOrigin
-> SyntaxExprRn
-> [SyntaxOpType]
-> ExpSigmaTypeFRR
-> ([Type] -> [Type] -> TcM (HsOverLit GhcTc))
-> IOEnv (Env TcGblEnv TcLclEnv) (HsOverLit GhcTc, SyntaxExprTc)
forall a.
CtOrigin
-> SyntaxExprRn
-> [SyntaxOpType]
-> ExpSigmaTypeFRR
-> ([Type] -> [Type] -> TcM a)
-> TcM (a, SyntaxExprTc)
tcSyntaxOp CtOrigin
orig SyntaxExpr GhcRn
SyntaxExprRn
ge [ExpSigmaTypeFRR -> SyntaxOpType
SynType ExpSigmaTypeFRR
pat_exp_ty, SyntaxOpType
SynRho]
(Type -> ExpSigmaTypeFRR
mkCheckExpType Type
boolTy) (([Type] -> [Type] -> TcM (HsOverLit GhcTc))
-> IOEnv (Env TcGblEnv TcLclEnv) (HsOverLit GhcTc, SyntaxExprTc))
-> ([Type] -> [Type] -> TcM (HsOverLit GhcTc))
-> IOEnv (Env TcGblEnv TcLclEnv) (HsOverLit GhcTc, SyntaxExprTc)
forall a b. (a -> b) -> a -> b
$
\ [Type
lit1_ty] [Type]
_ ->
HsOverLit GhcRn -> ExpSigmaTypeFRR -> TcM (HsOverLit GhcTc)
newOverloadedLit HsOverLit GhcRn
lit (Type -> ExpSigmaTypeFRR
mkCheckExpType Type
lit1_ty)
; ((HsOverLit GhcTc
lit2', HsWrapper
minus_wrap, TyCoVar
bndr_id), SyntaxExprTc
minus')
<- CtOrigin
-> SyntaxExprRn
-> [SyntaxOpType]
-> SyntaxOpType
-> ([Type] -> [Type] -> TcM (HsOverLit GhcTc, HsWrapper, TyCoVar))
-> TcM ((HsOverLit GhcTc, HsWrapper, TyCoVar), SyntaxExprTc)
forall a.
CtOrigin
-> SyntaxExprRn
-> [SyntaxOpType]
-> SyntaxOpType
-> ([Type] -> [Type] -> TcM a)
-> TcM (a, SyntaxExprTc)
tcSyntaxOpGen CtOrigin
orig SyntaxExpr GhcRn
SyntaxExprRn
minus [ExpSigmaTypeFRR -> SyntaxOpType
SynType ExpSigmaTypeFRR
pat_exp_ty, SyntaxOpType
SynRho] SyntaxOpType
SynAny (([Type] -> [Type] -> TcM (HsOverLit GhcTc, HsWrapper, TyCoVar))
-> TcM ((HsOverLit GhcTc, HsWrapper, TyCoVar), SyntaxExprTc))
-> ([Type] -> [Type] -> TcM (HsOverLit GhcTc, HsWrapper, TyCoVar))
-> TcM ((HsOverLit GhcTc, HsWrapper, TyCoVar), SyntaxExprTc)
forall a b. (a -> b) -> a -> b
$
\ [Type
lit2_ty, Type
var_ty] [Type]
_ ->
do { HsOverLit GhcTc
lit2' <- HsOverLit GhcRn -> ExpSigmaTypeFRR -> TcM (HsOverLit GhcTc)
newOverloadedLit HsOverLit GhcRn
lit (Type -> ExpSigmaTypeFRR
mkCheckExpType Type
lit2_ty)
; (HsWrapper
wrap, TyCoVar
bndr_id) <- SrcSpanAnnN -> TcM (HsWrapper, TyCoVar) -> TcM (HsWrapper, TyCoVar)
forall ann a. SrcSpanAnn' ann -> TcRn a -> TcRn a
setSrcSpanA SrcSpanAnnN
nm_loc (TcM (HsWrapper, TyCoVar) -> TcM (HsWrapper, TyCoVar))
-> TcM (HsWrapper, TyCoVar) -> TcM (HsWrapper, TyCoVar)
forall a b. (a -> b) -> a -> b
$
PatEnv
-> Name -> Scaled ExpSigmaTypeFRR -> TcM (HsWrapper, TyCoVar)
tcPatBndr PatEnv
penv Name
name (ExpSigmaTypeFRR -> Scaled ExpSigmaTypeFRR
forall a. a -> Scaled a
unrestricted (ExpSigmaTypeFRR -> Scaled ExpSigmaTypeFRR)
-> ExpSigmaTypeFRR -> Scaled ExpSigmaTypeFRR
forall a b. (a -> b) -> a -> b
$ Type -> ExpSigmaTypeFRR
mkCheckExpType Type
var_ty)
; (HsOverLit GhcTc, HsWrapper, TyCoVar)
-> TcM (HsOverLit GhcTc, HsWrapper, TyCoVar)
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return (HsOverLit GhcTc
lit2', HsWrapper
wrap, TyCoVar
bndr_id) }
; Type
pat_ty <- ExpSigmaTypeFRR -> TcM Type
forall (m :: * -> *). MonadIO m => ExpSigmaTypeFRR -> m Type
readExpType ExpSigmaTypeFRR
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 -> [Type] -> TcRn ()
instStupidTheta CtOrigin
orig [Class -> [Type] -> Type
mkClassPred Class
icls [Type
pat_ty]] }
; r
res <- Name -> TyCoVar -> TcM r -> TcM r
forall a. Name -> TyCoVar -> TcM a -> TcM a
tcExtendIdEnv1 Name
name TyCoVar
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 { 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 XNPlusKPat GhcTc
Type
pat_ty (SrcSpanAnnN -> TyCoVar -> GenLocated SrcSpanAnnN TyCoVar
forall l e. l -> e -> GenLocated l e
L SrcSpanAnnN
nm_loc TyCoVar
bndr_id) (SrcAnn NoEpAnns
-> HsOverLit GhcTc
-> GenLocated (SrcAnn NoEpAnns) (HsOverLit GhcTc)
forall l e. l -> e -> GenLocated l e
L SrcAnn NoEpAnns
loc HsOverLit GhcTc
lit1') HsOverLit GhcTc
lit2'
SyntaxExpr GhcTc
SyntaxExprTc
ge' SyntaxExpr GhcTc
SyntaxExprTc
minus''
; (Pat GhcTc, r) -> TcM (Pat GhcTc, r)
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return (HsWrapper -> Pat GhcTc -> Type -> Pat GhcTc
mkHsWrapPat HsWrapper
mult_wrap Pat GhcTc
pat' Type
pat_ty, r
res) }
SplicePat (HsUntypedSpliceTop ThModFinalizers
mod_finalizers Pat GhcRn
pat) HsUntypedSplice GhcRn
_ -> do
{ ThModFinalizers -> TcRn ()
addModFinalizersWithLclEnv ThModFinalizers
mod_finalizers
; Scaled ExpSigmaTypeFRR -> Checker (Pat GhcRn) (Pat GhcTc)
tc_pat Scaled ExpSigmaTypeFRR
pat_ty PatEnv
penv Pat GhcRn
pat TcM r
thing_inside }
SplicePat (HsUntypedSpliceNested Name
_) HsUntypedSplice GhcRn
_ -> String -> TcM (Pat GhcTc, r)
forall a. HasCallStack => String -> a
panic String
"tc_pat: nested splice in splice pat"
XPat (HsPatExpanded Pat GhcRn
lpat Pat GhcRn
rpat) -> do
{ (Pat GhcTc
rpat', r
res) <- Scaled ExpSigmaTypeFRR -> Checker (Pat GhcRn) (Pat GhcTc)
tc_pat Scaled ExpSigmaTypeFRR
pat_ty PatEnv
penv Pat GhcRn
rpat TcM r
thing_inside
; (Pat GhcTc, r) -> TcM (Pat GhcTc, r)
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return (XXPat GhcTc -> Pat GhcTc
forall p. XXPat p -> Pat p
XPat (XXPat GhcTc -> Pat GhcTc) -> XXPat GhcTc -> Pat GhcTc
forall a b. (a -> b) -> a -> b
$ Pat GhcRn -> Pat GhcTc -> XXPatGhcTc
ExpansionPat Pat GhcRn
lpat Pat GhcTc
rpat', r
res) }
tcPatSig :: Bool
-> HsPatSigType GhcRn
-> ExpSigmaType
-> TcM (TcType,
[(Name,TcTyVar)],
[(Name,TcTyVar)],
HsWrapper)
tcPatSig :: Bool
-> HsPatSigType GhcRn
-> ExpSigmaTypeFRR
-> TcM (Type, [(Name, TyCoVar)], [(Name, TyCoVar)], HsWrapper)
tcPatSig Bool
in_pat_bind HsPatSigType GhcRn
sig ExpSigmaTypeFRR
res_ty
= do { ([(Name, TyCoVar)]
sig_wcs, [(Name, TyCoVar)]
sig_tvs, Type
sig_ty) <- UserTypeCtxt
-> HoleMode
-> HsPatSigType GhcRn
-> ContextKind
-> TcM ([(Name, TyCoVar)], [(Name, TyCoVar)], Type)
tcHsPatSigType UserTypeCtxt
PatSigCtxt HoleMode
HM_Sig HsPatSigType GhcRn
sig ContextKind
OpenKind
; case [(Name, TyCoVar)] -> Maybe (NonEmpty (Name, TyCoVar))
forall a. [a] -> Maybe (NonEmpty a)
NE.nonEmpty [(Name, TyCoVar)]
sig_tvs of
Maybe (NonEmpty (Name, TyCoVar))
Nothing -> do {
HsWrapper
wrap <- (TidyEnv -> ZonkM (TidyEnv, SDoc))
-> TcM HsWrapper -> TcM HsWrapper
forall a. (TidyEnv -> ZonkM (TidyEnv, SDoc)) -> TcM a -> TcM a
addErrCtxtM (Type -> TidyEnv -> ZonkM (TidyEnv, SDoc)
mk_msg Type
sig_ty) (TcM HsWrapper -> TcM HsWrapper) -> TcM HsWrapper -> TcM HsWrapper
forall a b. (a -> b) -> a -> b
$
CtOrigin
-> UserTypeCtxt -> ExpSigmaTypeFRR -> Type -> TcM HsWrapper
tcSubTypePat CtOrigin
PatSigOrigin UserTypeCtxt
PatSigCtxt ExpSigmaTypeFRR
res_ty Type
sig_ty
; (Type, [(Name, TyCoVar)], [(Name, TyCoVar)], HsWrapper)
-> TcM (Type, [(Name, TyCoVar)], [(Name, TyCoVar)], HsWrapper)
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return (Type
sig_ty, [], [(Name, TyCoVar)]
sig_wcs, HsWrapper
wrap)
}
Just NonEmpty (Name, TyCoVar)
sig_tvs_ne -> do
Bool -> TcRn () -> TcRn ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when Bool
in_pat_bind
(TcRnMessage -> TcRn ()
addErr (NonEmpty (Name, TyCoVar) -> TcRnMessage
TcRnCannotBindScopedTyVarInPatSig NonEmpty (Name, TyCoVar)
sig_tvs_ne))
HsWrapper
wrap <- (TidyEnv -> ZonkM (TidyEnv, SDoc))
-> TcM HsWrapper -> TcM HsWrapper
forall a. (TidyEnv -> ZonkM (TidyEnv, SDoc)) -> TcM a -> TcM a
addErrCtxtM (Type -> TidyEnv -> ZonkM (TidyEnv, SDoc)
mk_msg Type
sig_ty) (TcM HsWrapper -> TcM HsWrapper) -> TcM HsWrapper -> TcM HsWrapper
forall a b. (a -> b) -> a -> b
$
CtOrigin
-> UserTypeCtxt -> ExpSigmaTypeFRR -> Type -> TcM HsWrapper
tcSubTypePat CtOrigin
PatSigOrigin UserTypeCtxt
PatSigCtxt ExpSigmaTypeFRR
res_ty Type
sig_ty
(Type, [(Name, TyCoVar)], [(Name, TyCoVar)], HsWrapper)
-> TcM (Type, [(Name, TyCoVar)], [(Name, TyCoVar)], HsWrapper)
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return (Type
sig_ty, [(Name, TyCoVar)]
sig_tvs, [(Name, TyCoVar)]
sig_wcs, HsWrapper
wrap)
}
where
mk_msg :: Type -> TidyEnv -> ZonkM (TidyEnv, SDoc)
mk_msg Type
sig_ty TidyEnv
tidy_env
= do { (TidyEnv
tidy_env, Type
sig_ty) <- TidyEnv -> Type -> ZonkM (TidyEnv, Type)
zonkTidyTcType TidyEnv
tidy_env Type
sig_ty
; Type
res_ty <- ExpSigmaTypeFRR -> ZonkM Type
forall (m :: * -> *). MonadIO m => ExpSigmaTypeFRR -> m Type
readExpType ExpSigmaTypeFRR
res_ty
; (TidyEnv
tidy_env, Type
res_ty) <- TidyEnv -> Type -> ZonkM (TidyEnv, Type)
zonkTidyTcType TidyEnv
tidy_env Type
res_ty
; let msg :: SDoc
msg = [SDoc] -> SDoc
forall doc. IsDoc doc => [doc] -> doc
vcat [ SDoc -> Int -> SDoc -> SDoc
hang (String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"When checking that the pattern signature:")
Int
4 (Type -> SDoc
forall a. Outputable a => a -> SDoc
ppr Type
sig_ty)
, Int -> SDoc -> SDoc
nest Int
2 (SDoc -> Int -> SDoc -> SDoc
hang (String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"fits the type of its context:")
Int
2 (Type -> SDoc
forall a. Outputable a => a -> SDoc
ppr Type
res_ty)) ]
; (TidyEnv, SDoc) -> ZonkM (TidyEnv, SDoc)
forall a. a -> ZonkM a
forall (m :: * -> *) a. Monad m => a -> m a
return (TidyEnv
tidy_env, SDoc
msg) }
tcConPat :: PatEnv -> LocatedN Name
-> Scaled ExpSigmaTypeFRR
-> HsConPatDetails GhcRn -> TcM a
-> TcM (Pat GhcTc, a)
tcConPat :: forall a.
PatEnv
-> GenLocated SrcSpanAnnN Name
-> Scaled ExpSigmaTypeFRR
-> HsConPatDetails GhcRn
-> TcM a
-> TcM (Pat GhcTc, a)
tcConPat PatEnv
penv con_lname :: GenLocated SrcSpanAnnN Name
con_lname@(L SrcSpanAnnN
_ Name
con_name) Scaled ExpSigmaTypeFRR
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 -> GenLocated SrcSpanAnnN Name
-> DataCon
-> Scaled ExpSigmaTypeFRR
-> Checker (HsConPatDetails GhcRn) (Pat GhcTc)
tcDataConPat GenLocated SrcSpanAnnN Name
con_lname DataCon
data_con Scaled ExpSigmaTypeFRR
pat_ty
PatEnv
penv HsConPatDetails GhcRn
arg_pats TcM a
thing_inside
PatSynCon PatSyn
pat_syn -> GenLocated SrcSpanAnnN Name
-> PatSyn
-> Scaled ExpSigmaTypeFRR
-> Checker (HsConPatDetails GhcRn) (Pat GhcTc)
tcPatSynPat GenLocated SrcSpanAnnN Name
con_lname PatSyn
pat_syn Scaled ExpSigmaTypeFRR
pat_ty
PatEnv
penv HsConPatDetails GhcRn
arg_pats TcM a
thing_inside
}
warnMonoLocalBinds :: TcM ()
warnMonoLocalBinds :: TcRn ()
warnMonoLocalBinds
= do { Bool
mono_local_binds <- Extension -> IOEnv (Env TcGblEnv TcLclEnv) Bool
forall gbl lcl. Extension -> TcRnIf gbl lcl Bool
xoptM Extension
LangExt.MonoLocalBinds
; Bool -> TcRn () -> TcRn ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
unless Bool
mono_local_binds (TcRn () -> TcRn ()) -> TcRn () -> TcRn ()
forall a b. (a -> b) -> a -> b
$
TcRnMessage -> TcRn ()
addDiagnostic TcRnMessage
TcRnGADTMonoLocalBinds
}
tcDataConPat :: LocatedN Name -> DataCon
-> Scaled ExpSigmaTypeFRR
-> Checker (HsConPatDetails GhcRn) (Pat GhcTc)
tcDataConPat :: GenLocated SrcSpanAnnN Name
-> DataCon
-> Scaled ExpSigmaTypeFRR
-> Checker (HsConPatDetails GhcRn) (Pat GhcTc)
tcDataConPat (L SrcSpanAnnN
con_span Name
con_name) DataCon
data_con Scaled ExpSigmaTypeFRR
pat_ty_scaled
PatEnv
penv HsConPatDetails GhcRn
arg_pats TcM r
thing_inside
= do { let tycon :: TyCon
tycon = DataCon -> TyCon
dataConTyCon DataCon
data_con
([TyCoVar]
univ_tvs, [TyCoVar]
ex_tvs, [EqSpec]
eq_spec, [Type]
theta, [Scaled Type]
arg_tys, Type
_)
= DataCon
-> ([TyCoVar], [TyCoVar], [EqSpec], [Type], [Scaled Type], Type)
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, [Type]
ctxt_res_tys) <- PatEnv
-> TyCon -> Scaled ExpSigmaTypeFRR -> TcM (HsWrapper, [Type])
matchExpectedConTy PatEnv
penv TyCon
tycon Scaled ExpSigmaTypeFRR
pat_ty_scaled
; Type
pat_ty <- ExpSigmaTypeFRR -> TcM Type
forall (m :: * -> *). MonadIO m => ExpSigmaTypeFRR -> m Type
readExpType (Scaled ExpSigmaTypeFRR -> ExpSigmaTypeFRR
forall a. Scaled a -> a
scaledThing Scaled ExpSigmaTypeFRR
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 -> [Type] -> TcRn ()
addDataConStupidTheta DataCon
data_con [Type]
ctxt_res_tys
; let all_arg_tys :: [Type]
all_arg_tys = [EqSpec] -> [Type]
eqSpecPreds [EqSpec]
eq_spec [Type] -> [Type] -> [Type]
forall a. [a] -> [a] -> [a]
++ [Type]
theta [Type] -> [Type] -> [Type]
forall a. [a] -> [a] -> [a]
++ ((Scaled Type -> Type) -> [Scaled Type] -> [Type]
forall a b. (a -> b) -> [a] -> [b]
map Scaled Type -> Type
forall a. Scaled a -> a
scaledThing [Scaled Type]
arg_tys)
; ConLike -> [TyCoVar] -> [Type] -> PatEnv -> TcRn ()
checkGADT (DataCon -> ConLike
RealDataCon DataCon
data_con) [TyCoVar]
ex_tvs [Type]
all_arg_tys PatEnv
penv
; Subst
tenv1 <- CtOrigin -> [TyCoVar] -> [Type] -> TcM Subst
instTyVarsWith CtOrigin
PatOrigin [TyCoVar]
univ_tvs [Type]
ctxt_res_tys
; let mc :: HsMatchContext GhcTc
mc = case PatEnv -> PatCtxt
pe_ctxt PatEnv
penv of
LamPat HsMatchContext GhcTc
mc -> HsMatchContext GhcTc
mc
LetPat {} -> HsMatchContext GhcTc
forall p. HsMatchContext p
PatBindRhs
; SkolemInfo
skol_info <- SkolemInfoAnon -> IOEnv (Env TcGblEnv TcLclEnv) SkolemInfo
forall (m :: * -> *). MonadIO m => SkolemInfoAnon -> m SkolemInfo
mkSkolemInfo (ConLike -> HsMatchContext GhcTc -> SkolemInfoAnon
PatSkol (DataCon -> ConLike
RealDataCon DataCon
data_con) HsMatchContext GhcTc
mc)
; (Subst
tenv, [TyCoVar]
ex_tvs') <- SkolemInfo -> Subst -> [TyCoVar] -> TcM (Subst, [TyCoVar])
tcInstSuperSkolTyVarsX SkolemInfo
skol_info Subst
tenv1 [TyCoVar]
ex_tvs
; let arg_tys' :: [Scaled Type]
arg_tys' = HasDebugCallStack => Subst -> [Scaled Type] -> [Scaled Type]
Subst -> [Scaled Type] -> [Scaled Type]
substScaledTys Subst
tenv [Scaled Type]
arg_tys
pat_mult :: Type
pat_mult = Scaled ExpSigmaTypeFRR -> Type
forall a. Scaled a -> Type
scaledMult Scaled ExpSigmaTypeFRR
pat_ty_scaled
arg_tys_scaled :: [Scaled Type]
arg_tys_scaled = (Scaled Type -> Scaled Type) -> [Scaled Type] -> [Scaled Type]
forall a b. (a -> b) -> [a] -> [b]
map (Type -> Scaled Type -> Scaled Type
forall a. Type -> Scaled a -> Scaled a
scaleScaled Type
pat_mult) [Scaled Type]
arg_tys'
con_like :: ConLike
con_like = DataCon -> ConLike
RealDataCon DataCon
data_con
; DataCon -> [Scaled Type] -> TcRn ()
checkFixedRuntimeRep DataCon
data_con [Scaled Type]
arg_tys'
; String -> SDoc -> TcRn ()
traceTc String
"tcConPat" ([SDoc] -> SDoc
forall doc. IsDoc doc => [doc] -> doc
vcat [ String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"con_name:" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> Name -> SDoc
forall a. Outputable a => a -> SDoc
ppr Name
con_name
, String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"univ_tvs:" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> [TyCoVar] -> SDoc
pprTyVars [TyCoVar]
univ_tvs
, String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"ex_tvs:" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> [TyCoVar] -> SDoc
pprTyVars [TyCoVar]
ex_tvs
, String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"eq_spec:" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> [EqSpec] -> SDoc
forall a. Outputable a => a -> SDoc
ppr [EqSpec]
eq_spec
, String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"theta:" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> [Type] -> SDoc
forall a. Outputable a => a -> SDoc
ppr [Type]
theta
, String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"ex_tvs':" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> [TyCoVar] -> SDoc
pprTyVars [TyCoVar]
ex_tvs'
, String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"ctxt_res_tys:" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> [Type] -> SDoc
forall a. Outputable a => a -> SDoc
ppr [Type]
ctxt_res_tys
, String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"pat_ty:" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> Type -> SDoc
forall a. Outputable a => a -> SDoc
ppr Type
pat_ty
, String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"arg_tys':" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> [Scaled Type] -> SDoc
forall a. Outputable a => a -> SDoc
ppr [Scaled Type]
arg_tys'
, String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"arg_pats" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> HsConDetails
(HsConPatTyArg GhcRn)
(GenLocated SrcSpanAnnA (Pat GhcRn))
(HsRecFields GhcRn (GenLocated SrcSpanAnnA (Pat GhcRn)))
-> SDoc
forall a. Outputable a => a -> SDoc
ppr HsConPatDetails GhcRn
HsConDetails
(HsConPatTyArg GhcRn)
(GenLocated SrcSpanAnnA (Pat GhcRn))
(HsRecFields GhcRn (GenLocated SrcSpanAnnA (Pat GhcRn)))
arg_pats ])
; ([(HsConPatTyArg GhcRn, TyCoVar)]
univ_ty_args, [(HsConPatTyArg GhcRn, TyCoVar)]
ex_ty_args) <- ConLike
-> HsConPatDetails GhcRn
-> TcM
([(HsConPatTyArg GhcRn, TyCoVar)],
[(HsConPatTyArg GhcRn, TyCoVar)])
splitConTyArgs ConLike
con_like HsConPatDetails GhcRn
arg_pats
; if [TyCoVar] -> Bool
forall a. [a] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [TyCoVar]
ex_tvs Bool -> Bool -> Bool
&& [EqSpec] -> Bool
forall a. [a] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [EqSpec]
eq_spec Bool -> Bool -> Bool
&& [Type] -> Bool
forall a. [a] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [Type]
theta
then do {
(HsConDetails
(HsConPatTyArg GhcRn)
(GenLocated SrcSpanAnnA (Pat GhcTc))
(HsRecFields GhcTc (GenLocated SrcSpanAnnA (Pat GhcTc)))
arg_pats', r
res) <- Subst
-> PatEnv
-> [(HsConPatTyArg GhcRn, TyCoVar)]
-> TcM
(HsConDetails
(HsConPatTyArg GhcRn)
(GenLocated SrcSpanAnnA (Pat GhcTc))
(HsRecFields GhcTc (GenLocated SrcSpanAnnA (Pat GhcTc))),
r)
-> TcM
(HsConDetails
(HsConPatTyArg GhcRn)
(GenLocated SrcSpanAnnA (Pat GhcTc))
(HsRecFields GhcTc (GenLocated SrcSpanAnnA (Pat GhcTc))),
r)
forall a.
Subst
-> PatEnv -> [(HsConPatTyArg GhcRn, TyCoVar)] -> TcM a -> TcM a
tcConTyArgs Subst
tenv PatEnv
penv [(HsConPatTyArg GhcRn, TyCoVar)]
univ_ty_args (TcM
(HsConDetails
(HsConPatTyArg GhcRn)
(GenLocated SrcSpanAnnA (Pat GhcTc))
(HsRecFields GhcTc (GenLocated SrcSpanAnnA (Pat GhcTc))),
r)
-> TcM
(HsConDetails
(HsConPatTyArg GhcRn)
(GenLocated SrcSpanAnnA (Pat GhcTc))
(HsRecFields GhcTc (GenLocated SrcSpanAnnA (Pat GhcTc))),
r))
-> TcM
(HsConDetails
(HsConPatTyArg GhcRn)
(GenLocated SrcSpanAnnA (Pat GhcTc))
(HsRecFields GhcTc (GenLocated SrcSpanAnnA (Pat GhcTc))),
r)
-> TcM
(HsConDetails
(HsConPatTyArg GhcRn)
(GenLocated SrcSpanAnnA (Pat GhcTc))
(HsRecFields GhcTc (GenLocated SrcSpanAnnA (Pat GhcTc))),
r)
forall a b. (a -> b) -> a -> b
$
ConLike
-> [Scaled Type]
-> Checker (HsConPatDetails GhcRn) (HsConPatDetails GhcTc)
tcConValArgs ConLike
con_like [Scaled Type]
arg_tys_scaled
PatEnv
penv HsConPatDetails GhcRn
arg_pats TcM r
thing_inside
; let res_pat :: Pat GhcTc
res_pat = ConPat { pat_con :: XRec GhcTc (ConLikeP GhcTc)
pat_con = XRec GhcTc (ConLikeP GhcTc)
GenLocated SrcSpanAnnN ConLike
header
, pat_args :: HsConPatDetails GhcTc
pat_args = HsConPatDetails GhcTc
HsConDetails
(HsConPatTyArg GhcRn)
(GenLocated SrcSpanAnnA (Pat GhcTc))
(HsRecFields GhcTc (GenLocated SrcSpanAnnA (Pat GhcTc)))
arg_pats'
, pat_con_ext :: XConPat GhcTc
pat_con_ext = ConPatTc
{ cpt_tvs :: [TyCoVar]
cpt_tvs = [], cpt_dicts :: [TyCoVar]
cpt_dicts = []
, cpt_binds :: TcEvBinds
cpt_binds = TcEvBinds
emptyTcEvBinds
, cpt_arg_tys :: [Type]
cpt_arg_tys = [Type]
ctxt_res_tys
, cpt_wrap :: HsWrapper
cpt_wrap = HsWrapper
idHsWrapper
}
}
; (Pat GhcTc, r) -> TcM (Pat GhcTc, r)
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return (HsWrapper -> Pat GhcTc -> Type -> Pat GhcTc
mkHsWrapPat HsWrapper
wrap Pat GhcTc
res_pat Type
pat_ty, r
res) }
else do
{ let theta' :: [Type]
theta' = HasDebugCallStack => Subst -> [Type] -> [Type]
Subst -> [Type] -> [Type]
substTheta Subst
tenv ([EqSpec] -> [Type]
eqSpecPreds [EqSpec]
eq_spec [Type] -> [Type] -> [Type]
forall a. [a] -> [a] -> [a]
++ [Type]
theta)
; Bool -> TcRn () -> TcRn ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (Bool -> Bool
not ([EqSpec] -> Bool
forall a. [a] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [EqSpec]
eq_spec) Bool -> Bool -> Bool
|| (Type -> Bool) -> [Type] -> Bool
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
any Type -> Bool
isEqPred [Type]
theta) TcRn ()
warnMonoLocalBinds
; [TyCoVar]
given <- [Type] -> TcM [TyCoVar]
newEvVars [Type]
theta'
; (TcEvBinds
ev_binds, (HsConDetails
(HsConPatTyArg GhcRn)
(GenLocated SrcSpanAnnA (Pat GhcTc))
(HsRecFields GhcTc (GenLocated SrcSpanAnnA (Pat GhcTc)))
arg_pats', r
res))
<-
Subst
-> PatEnv
-> [(HsConPatTyArg GhcRn, TyCoVar)]
-> TcM
(TcEvBinds,
(HsConDetails
(HsConPatTyArg GhcRn)
(GenLocated SrcSpanAnnA (Pat GhcTc))
(HsRecFields GhcTc (GenLocated SrcSpanAnnA (Pat GhcTc))),
r))
-> TcM
(TcEvBinds,
(HsConDetails
(HsConPatTyArg GhcRn)
(GenLocated SrcSpanAnnA (Pat GhcTc))
(HsRecFields GhcTc (GenLocated SrcSpanAnnA (Pat GhcTc))),
r))
forall a.
Subst
-> PatEnv -> [(HsConPatTyArg GhcRn, TyCoVar)] -> TcM a -> TcM a
tcConTyArgs Subst
tenv PatEnv
penv [(HsConPatTyArg GhcRn, TyCoVar)]
univ_ty_args (TcM
(TcEvBinds,
(HsConDetails
(HsConPatTyArg GhcRn)
(GenLocated SrcSpanAnnA (Pat GhcTc))
(HsRecFields GhcTc (GenLocated SrcSpanAnnA (Pat GhcTc))),
r))
-> TcM
(TcEvBinds,
(HsConDetails
(HsConPatTyArg GhcRn)
(GenLocated SrcSpanAnnA (Pat GhcTc))
(HsRecFields GhcTc (GenLocated SrcSpanAnnA (Pat GhcTc))),
r)))
-> TcM
(TcEvBinds,
(HsConDetails
(HsConPatTyArg GhcRn)
(GenLocated SrcSpanAnnA (Pat GhcTc))
(HsRecFields GhcTc (GenLocated SrcSpanAnnA (Pat GhcTc))),
r))
-> TcM
(TcEvBinds,
(HsConDetails
(HsConPatTyArg GhcRn)
(GenLocated SrcSpanAnnA (Pat GhcTc))
(HsRecFields GhcTc (GenLocated SrcSpanAnnA (Pat GhcTc))),
r))
forall a b. (a -> b) -> a -> b
$
SkolemInfoAnon
-> [TyCoVar]
-> [TyCoVar]
-> TcM
(HsConDetails
(HsConPatTyArg GhcRn)
(GenLocated SrcSpanAnnA (Pat GhcTc))
(HsRecFields GhcTc (GenLocated SrcSpanAnnA (Pat GhcTc))),
r)
-> TcM
(TcEvBinds,
(HsConDetails
(HsConPatTyArg GhcRn)
(GenLocated SrcSpanAnnA (Pat GhcTc))
(HsRecFields GhcTc (GenLocated SrcSpanAnnA (Pat GhcTc))),
r))
forall result.
SkolemInfoAnon
-> [TyCoVar] -> [TyCoVar] -> TcM result -> TcM (TcEvBinds, result)
checkConstraints (SkolemInfo -> SkolemInfoAnon
getSkolemInfo SkolemInfo
skol_info) [TyCoVar]
ex_tvs' [TyCoVar]
given (TcM
(HsConDetails
(HsConPatTyArg GhcRn)
(GenLocated SrcSpanAnnA (Pat GhcTc))
(HsRecFields GhcTc (GenLocated SrcSpanAnnA (Pat GhcTc))),
r)
-> TcM
(TcEvBinds,
(HsConDetails
(HsConPatTyArg GhcRn)
(GenLocated SrcSpanAnnA (Pat GhcTc))
(HsRecFields GhcTc (GenLocated SrcSpanAnnA (Pat GhcTc))),
r)))
-> TcM
(HsConDetails
(HsConPatTyArg GhcRn)
(GenLocated SrcSpanAnnA (Pat GhcTc))
(HsRecFields GhcTc (GenLocated SrcSpanAnnA (Pat GhcTc))),
r)
-> TcM
(TcEvBinds,
(HsConDetails
(HsConPatTyArg GhcRn)
(GenLocated SrcSpanAnnA (Pat GhcTc))
(HsRecFields GhcTc (GenLocated SrcSpanAnnA (Pat GhcTc))),
r))
forall a b. (a -> b) -> a -> b
$
Subst
-> PatEnv
-> [(HsConPatTyArg GhcRn, TyCoVar)]
-> TcM
(HsConDetails
(HsConPatTyArg GhcRn)
(GenLocated SrcSpanAnnA (Pat GhcTc))
(HsRecFields GhcTc (GenLocated SrcSpanAnnA (Pat GhcTc))),
r)
-> TcM
(HsConDetails
(HsConPatTyArg GhcRn)
(GenLocated SrcSpanAnnA (Pat GhcTc))
(HsRecFields GhcTc (GenLocated SrcSpanAnnA (Pat GhcTc))),
r)
forall a.
Subst
-> PatEnv -> [(HsConPatTyArg GhcRn, TyCoVar)] -> TcM a -> TcM a
tcConTyArgs Subst
tenv PatEnv
penv [(HsConPatTyArg GhcRn, TyCoVar)]
ex_ty_args (TcM
(HsConDetails
(HsConPatTyArg GhcRn)
(GenLocated SrcSpanAnnA (Pat GhcTc))
(HsRecFields GhcTc (GenLocated SrcSpanAnnA (Pat GhcTc))),
r)
-> TcM
(HsConDetails
(HsConPatTyArg GhcRn)
(GenLocated SrcSpanAnnA (Pat GhcTc))
(HsRecFields GhcTc (GenLocated SrcSpanAnnA (Pat GhcTc))),
r))
-> TcM
(HsConDetails
(HsConPatTyArg GhcRn)
(GenLocated SrcSpanAnnA (Pat GhcTc))
(HsRecFields GhcTc (GenLocated SrcSpanAnnA (Pat GhcTc))),
r)
-> TcM
(HsConDetails
(HsConPatTyArg GhcRn)
(GenLocated SrcSpanAnnA (Pat GhcTc))
(HsRecFields GhcTc (GenLocated SrcSpanAnnA (Pat GhcTc))),
r)
forall a b. (a -> b) -> a -> b
$
ConLike
-> [Scaled Type]
-> Checker (HsConPatDetails GhcRn) (HsConPatDetails GhcTc)
tcConValArgs ConLike
con_like [Scaled Type]
arg_tys_scaled PatEnv
penv HsConPatDetails GhcRn
arg_pats TcM r
thing_inside
; let res_pat :: Pat GhcTc
res_pat = ConPat
{ pat_con :: XRec GhcTc (ConLikeP GhcTc)
pat_con = XRec GhcTc (ConLikeP GhcTc)
GenLocated SrcSpanAnnN ConLike
header
, pat_args :: HsConPatDetails GhcTc
pat_args = HsConPatDetails GhcTc
HsConDetails
(HsConPatTyArg GhcRn)
(GenLocated SrcSpanAnnA (Pat GhcTc))
(HsRecFields GhcTc (GenLocated SrcSpanAnnA (Pat GhcTc)))
arg_pats'
, pat_con_ext :: XConPat GhcTc
pat_con_ext = ConPatTc
{ cpt_tvs :: [TyCoVar]
cpt_tvs = [TyCoVar]
ex_tvs'
, cpt_dicts :: [TyCoVar]
cpt_dicts = [TyCoVar]
given
, cpt_binds :: TcEvBinds
cpt_binds = TcEvBinds
ev_binds
, cpt_arg_tys :: [Type]
cpt_arg_tys = [Type]
ctxt_res_tys
, cpt_wrap :: HsWrapper
cpt_wrap = HsWrapper
idHsWrapper
}
}
; (Pat GhcTc, r) -> TcM (Pat GhcTc, r)
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return (HsWrapper -> Pat GhcTc -> Type -> Pat GhcTc
mkHsWrapPat HsWrapper
wrap Pat GhcTc
res_pat Type
pat_ty, r
res)
} }
tcPatSynPat :: LocatedN Name -> PatSyn
-> Scaled ExpSigmaType
-> Checker (HsConPatDetails GhcRn) (Pat GhcTc)
tcPatSynPat :: GenLocated SrcSpanAnnN Name
-> PatSyn
-> Scaled ExpSigmaTypeFRR
-> Checker (HsConPatDetails GhcRn) (Pat GhcTc)
tcPatSynPat (L SrcSpanAnnN
con_span Name
con_name) PatSyn
pat_syn Scaled ExpSigmaTypeFRR
pat_ty PatEnv
penv HsConPatDetails GhcRn
arg_pats TcM r
thing_inside
= do { let ([TyCoVar]
univ_tvs, [Type]
req_theta, [TyCoVar]
ex_tvs, [Type]
prov_theta, [Scaled Type]
arg_tys, Type
ty) = PatSyn
-> ([TyCoVar], [Type], [TyCoVar], [Type], [Scaled Type], Type)
patSynSig PatSyn
pat_syn
; (Subst
subst, [TyCoVar]
univ_tvs') <- [TyCoVar] -> TcM (Subst, [TyCoVar])
newMetaTyVars [TyCoVar]
univ_tvs
; let all_arg_tys :: [Type]
all_arg_tys = Type
ty Type -> [Type] -> [Type]
forall a. a -> [a] -> [a]
: [Type]
prov_theta [Type] -> [Type] -> [Type]
forall a. [a] -> [a] -> [a]
++ ((Scaled Type -> Type) -> [Scaled Type] -> [Type]
forall a b. (a -> b) -> [a] -> [b]
map Scaled Type -> Type
forall a. Scaled a -> a
scaledThing [Scaled Type]
arg_tys)
; ConLike -> [TyCoVar] -> [Type] -> PatEnv -> TcRn ()
checkGADT (PatSyn -> ConLike
PatSynCon PatSyn
pat_syn) [TyCoVar]
ex_tvs [Type]
all_arg_tys PatEnv
penv
; SkolemInfo
skol_info <- case PatEnv -> PatCtxt
pe_ctxt PatEnv
penv of
LamPat HsMatchContext GhcTc
mc -> SkolemInfoAnon -> IOEnv (Env TcGblEnv TcLclEnv) SkolemInfo
forall (m :: * -> *). MonadIO m => SkolemInfoAnon -> m SkolemInfo
mkSkolemInfo (ConLike -> HsMatchContext GhcTc -> SkolemInfoAnon
PatSkol (PatSyn -> ConLike
PatSynCon PatSyn
pat_syn) HsMatchContext GhcTc
mc)
LetPat {} -> SkolemInfo -> IOEnv (Env TcGblEnv TcLclEnv) SkolemInfo
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return SkolemInfo
HasDebugCallStack => SkolemInfo
unkSkol
; (Subst
tenv, [TyCoVar]
ex_tvs') <- SkolemInfo -> Subst -> [TyCoVar] -> TcM (Subst, [TyCoVar])
tcInstSuperSkolTyVarsX SkolemInfo
skol_info Subst
subst [TyCoVar]
ex_tvs
; let ty' :: Type
ty' = HasDebugCallStack => Subst -> Type -> Type
Subst -> Type -> Type
substTy Subst
tenv Type
ty
arg_tys' :: [Scaled Type]
arg_tys' = HasDebugCallStack => Subst -> [Scaled Type] -> [Scaled Type]
Subst -> [Scaled Type] -> [Scaled Type]
substScaledTys Subst
tenv [Scaled Type]
arg_tys
pat_mult :: Type
pat_mult = Scaled ExpSigmaTypeFRR -> Type
forall a. Scaled a -> Type
scaledMult Scaled ExpSigmaTypeFRR
pat_ty
arg_tys_scaled :: [Scaled Type]
arg_tys_scaled = (Scaled Type -> Scaled Type) -> [Scaled Type] -> [Scaled Type]
forall a b. (a -> b) -> [a] -> [b]
map (Type -> Scaled Type -> Scaled Type
forall a. Type -> Scaled a -> Scaled a
scaleScaled Type
pat_mult) [Scaled Type]
arg_tys'
prov_theta' :: [Type]
prov_theta' = HasDebugCallStack => Subst -> [Type] -> [Type]
Subst -> [Type] -> [Type]
substTheta Subst
tenv [Type]
prov_theta
req_theta' :: [Type]
req_theta' = HasDebugCallStack => Subst -> [Type] -> [Type]
Subst -> [Type] -> [Type]
substTheta Subst
tenv [Type]
req_theta
con_like :: ConLike
con_like = PatSyn -> ConLike
PatSynCon PatSyn
pat_syn
; Bool -> TcRn () -> TcRn ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when ((Type -> Bool) -> [Type] -> Bool
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
any Type -> Bool
isEqPred [Type]
prov_theta) TcRn ()
warnMonoLocalBinds
; HsWrapper
mult_wrap <- Scaled ExpSigmaTypeFRR -> TcM HsWrapper
forall a. Scaled a -> TcM HsWrapper
checkManyPattern Scaled ExpSigmaTypeFRR
pat_ty
; ([(HsConPatTyArg GhcRn, TyCoVar)]
univ_ty_args, [(HsConPatTyArg GhcRn, TyCoVar)]
ex_ty_args) <- ConLike
-> HsConPatDetails GhcRn
-> TcM
([(HsConPatTyArg GhcRn, TyCoVar)],
[(HsConPatTyArg GhcRn, TyCoVar)])
splitConTyArgs ConLike
con_like HsConPatDetails GhcRn
arg_pats
; HsWrapper
wrap <- PatEnv -> ExpSigmaTypeFRR -> Type -> TcM HsWrapper
tc_sub_type PatEnv
penv (Scaled ExpSigmaTypeFRR -> ExpSigmaTypeFRR
forall a. Scaled a -> a
scaledThing Scaled ExpSigmaTypeFRR
pat_ty) Type
ty'
; String -> SDoc -> TcRn ()
traceTc String
"tcPatSynPat" (SDoc -> TcRn ()) -> SDoc -> TcRn ()
forall a b. (a -> b) -> a -> b
$
[SDoc] -> SDoc
forall doc. IsDoc doc => [doc] -> doc
vcat [ String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"Pat syn:" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> PatSyn -> SDoc
forall a. Outputable a => a -> SDoc
ppr PatSyn
pat_syn
, String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"Expected type:" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> Scaled ExpSigmaTypeFRR -> SDoc
forall a. Outputable a => a -> SDoc
ppr Scaled ExpSigmaTypeFRR
pat_ty
, String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"Pat res ty:" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> Type -> SDoc
forall a. Outputable a => a -> SDoc
ppr Type
ty'
, String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"ex_tvs':" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> [TyCoVar] -> SDoc
pprTyVars [TyCoVar]
ex_tvs'
, String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"prov_theta':" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> [Type] -> SDoc
forall a. Outputable a => a -> SDoc
ppr [Type]
prov_theta'
, String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"req_theta':" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> [Type] -> SDoc
forall a. Outputable a => a -> SDoc
ppr [Type]
req_theta'
, String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"arg_tys':" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> [Scaled Type] -> SDoc
forall a. Outputable a => a -> SDoc
ppr [Scaled Type]
arg_tys'
, String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"univ_ty_args:" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> [(HsConPatTyArg GhcRn, TyCoVar)] -> SDoc
forall a. Outputable a => a -> SDoc
ppr [(HsConPatTyArg GhcRn, TyCoVar)]
univ_ty_args
, String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"ex_ty_args:" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> [(HsConPatTyArg GhcRn, TyCoVar)] -> SDoc
forall a. Outputable a => a -> SDoc
ppr [(HsConPatTyArg GhcRn, TyCoVar)]
ex_ty_args ]
; HsWrapper
req_wrap <- CtOrigin -> [Type] -> [Type] -> TcM HsWrapper
instCall (Name -> CtOrigin
OccurrenceOf Name
con_name) ([TyCoVar] -> [Type]
mkTyVarTys [TyCoVar]
univ_tvs') [Type]
req_theta'
; String -> SDoc -> TcRn ()
traceTc String
"instCall" (HsWrapper -> SDoc
forall a. Outputable a => a -> SDoc
ppr HsWrapper
req_wrap)
; let
bad_arg_tys :: [(Int, Scaled Type)]
bad_arg_tys :: [(Int, Scaled Type)]
bad_arg_tys = ((Int, Scaled Type) -> Bool)
-> [(Int, Scaled Type)] -> [(Int, Scaled Type)]
forall a. (a -> Bool) -> [a] -> [a]
filter (\ (Int
_, Scaled Type
_ Type
arg_ty) -> HasDebugCallStack => Type -> Maybe Levity
Type -> Maybe Levity
typeLevity_maybe Type
arg_ty Maybe Levity -> Maybe Levity -> Bool
forall a. Eq a => a -> a -> Bool
== Maybe Levity
forall a. Maybe a
Nothing)
([(Int, Scaled Type)] -> [(Int, Scaled Type)])
-> [(Int, Scaled Type)] -> [(Int, Scaled Type)]
forall a b. (a -> b) -> a -> b
$ [Int] -> [Scaled Type] -> [(Int, Scaled Type)]
forall a b. [a] -> [b] -> [(a, b)]
zip [Int
0..] [Scaled Type]
arg_tys'
; Bool -> SDoc -> TcRn ()
forall (m :: * -> *).
(HasCallStack, Applicative m) =>
Bool -> SDoc -> m ()
massertPpr ([(Int, Scaled Type)] -> Bool
forall a. [a] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [(Int, Scaled Type)]
bad_arg_tys) (SDoc -> TcRn ()) -> SDoc -> TcRn ()
forall a b. (a -> b) -> a -> b
$
[SDoc] -> SDoc
forall doc. IsDoc doc => [doc] -> doc
vcat [ String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"tcPatSynPat: pattern arguments do not have a fixed RuntimeRep"
, String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"bad_arg_tys:" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> [(Int, Scaled Type)] -> SDoc
forall a. Outputable a => a -> SDoc
ppr [(Int, Scaled Type)]
bad_arg_tys ]
; String -> SDoc -> TcRn ()
traceTc String
"checkConstraints {" SDoc
forall doc. IsOutput doc => doc
Outputable.empty
; [TyCoVar]
prov_dicts' <- [Type] -> TcM [TyCoVar]
newEvVars [Type]
prov_theta'
; (TcEvBinds
ev_binds, (HsConDetails
(HsConPatTyArg GhcRn)
(GenLocated SrcSpanAnnA (Pat GhcTc))
(HsRecFields GhcTc (GenLocated SrcSpanAnnA (Pat GhcTc)))
arg_pats', r
res))
<-
Subst
-> PatEnv
-> [(HsConPatTyArg GhcRn, TyCoVar)]
-> TcM
(TcEvBinds,
(HsConDetails
(HsConPatTyArg GhcRn)
(GenLocated SrcSpanAnnA (Pat GhcTc))
(HsRecFields GhcTc (GenLocated SrcSpanAnnA (Pat GhcTc))),
r))
-> TcM
(TcEvBinds,
(HsConDetails
(HsConPatTyArg GhcRn)
(GenLocated SrcSpanAnnA (Pat GhcTc))
(HsRecFields GhcTc (GenLocated SrcSpanAnnA (Pat GhcTc))),
r))
forall a.
Subst
-> PatEnv -> [(HsConPatTyArg GhcRn, TyCoVar)] -> TcM a -> TcM a
tcConTyArgs Subst
tenv PatEnv
penv [(HsConPatTyArg GhcRn, TyCoVar)]
univ_ty_args (TcM
(TcEvBinds,
(HsConDetails
(HsConPatTyArg GhcRn)
(GenLocated SrcSpanAnnA (Pat GhcTc))
(HsRecFields GhcTc (GenLocated SrcSpanAnnA (Pat GhcTc))),
r))
-> TcM
(TcEvBinds,
(HsConDetails
(HsConPatTyArg GhcRn)
(GenLocated SrcSpanAnnA (Pat GhcTc))
(HsRecFields GhcTc (GenLocated SrcSpanAnnA (Pat GhcTc))),
r)))
-> TcM
(TcEvBinds,
(HsConDetails
(HsConPatTyArg GhcRn)
(GenLocated SrcSpanAnnA (Pat GhcTc))
(HsRecFields GhcTc (GenLocated SrcSpanAnnA (Pat GhcTc))),
r))
-> TcM
(TcEvBinds,
(HsConDetails
(HsConPatTyArg GhcRn)
(GenLocated SrcSpanAnnA (Pat GhcTc))
(HsRecFields GhcTc (GenLocated SrcSpanAnnA (Pat GhcTc))),
r))
forall a b. (a -> b) -> a -> b
$
SkolemInfoAnon
-> [TyCoVar]
-> [TyCoVar]
-> TcM
(HsConDetails
(HsConPatTyArg GhcRn)
(GenLocated SrcSpanAnnA (Pat GhcTc))
(HsRecFields GhcTc (GenLocated SrcSpanAnnA (Pat GhcTc))),
r)
-> TcM
(TcEvBinds,
(HsConDetails
(HsConPatTyArg GhcRn)
(GenLocated SrcSpanAnnA (Pat GhcTc))
(HsRecFields GhcTc (GenLocated SrcSpanAnnA (Pat GhcTc))),
r))
forall result.
SkolemInfoAnon
-> [TyCoVar] -> [TyCoVar] -> TcM result -> TcM (TcEvBinds, result)
checkConstraints (SkolemInfo -> SkolemInfoAnon
getSkolemInfo SkolemInfo
skol_info) [TyCoVar]
ex_tvs' [TyCoVar]
prov_dicts' (TcM
(HsConDetails
(HsConPatTyArg GhcRn)
(GenLocated SrcSpanAnnA (Pat GhcTc))
(HsRecFields GhcTc (GenLocated SrcSpanAnnA (Pat GhcTc))),
r)
-> TcM
(TcEvBinds,
(HsConDetails
(HsConPatTyArg GhcRn)
(GenLocated SrcSpanAnnA (Pat GhcTc))
(HsRecFields GhcTc (GenLocated SrcSpanAnnA (Pat GhcTc))),
r)))
-> TcM
(HsConDetails
(HsConPatTyArg GhcRn)
(GenLocated SrcSpanAnnA (Pat GhcTc))
(HsRecFields GhcTc (GenLocated SrcSpanAnnA (Pat GhcTc))),
r)
-> TcM
(TcEvBinds,
(HsConDetails
(HsConPatTyArg GhcRn)
(GenLocated SrcSpanAnnA (Pat GhcTc))
(HsRecFields GhcTc (GenLocated SrcSpanAnnA (Pat GhcTc))),
r))
forall a b. (a -> b) -> a -> b
$
Subst
-> PatEnv
-> [(HsConPatTyArg GhcRn, TyCoVar)]
-> TcM
(HsConDetails
(HsConPatTyArg GhcRn)
(GenLocated SrcSpanAnnA (Pat GhcTc))
(HsRecFields GhcTc (GenLocated SrcSpanAnnA (Pat GhcTc))),
r)
-> TcM
(HsConDetails
(HsConPatTyArg GhcRn)
(GenLocated SrcSpanAnnA (Pat GhcTc))
(HsRecFields GhcTc (GenLocated SrcSpanAnnA (Pat GhcTc))),
r)
forall a.
Subst
-> PatEnv -> [(HsConPatTyArg GhcRn, TyCoVar)] -> TcM a -> TcM a
tcConTyArgs Subst
tenv PatEnv
penv [(HsConPatTyArg GhcRn, TyCoVar)]
ex_ty_args (TcM
(HsConDetails
(HsConPatTyArg GhcRn)
(GenLocated SrcSpanAnnA (Pat GhcTc))
(HsRecFields GhcTc (GenLocated SrcSpanAnnA (Pat GhcTc))),
r)
-> TcM
(HsConDetails
(HsConPatTyArg GhcRn)
(GenLocated SrcSpanAnnA (Pat GhcTc))
(HsRecFields GhcTc (GenLocated SrcSpanAnnA (Pat GhcTc))),
r))
-> TcM
(HsConDetails
(HsConPatTyArg GhcRn)
(GenLocated SrcSpanAnnA (Pat GhcTc))
(HsRecFields GhcTc (GenLocated SrcSpanAnnA (Pat GhcTc))),
r)
-> TcM
(HsConDetails
(HsConPatTyArg GhcRn)
(GenLocated SrcSpanAnnA (Pat GhcTc))
(HsRecFields GhcTc (GenLocated SrcSpanAnnA (Pat GhcTc))),
r)
forall a b. (a -> b) -> a -> b
$
ConLike
-> [Scaled Type]
-> Checker (HsConPatDetails GhcRn) (HsConPatDetails GhcTc)
tcConValArgs ConLike
con_like [Scaled Type]
arg_tys_scaled PatEnv
penv HsConPatDetails GhcRn
arg_pats (TcM r -> TcM (HsConPatDetails GhcTc, r))
-> TcM r -> TcM (HsConPatDetails GhcTc, r)
forall a b. (a -> b) -> a -> b
$
TcM r
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 { 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 = HsConPatDetails GhcTc
HsConDetails
(HsConPatTyArg GhcRn)
(GenLocated SrcSpanAnnA (Pat GhcTc))
(HsRecFields GhcTc (GenLocated SrcSpanAnnA (Pat GhcTc)))
arg_pats'
, pat_con_ext :: XConPat GhcTc
pat_con_ext = ConPatTc
{ cpt_tvs :: [TyCoVar]
cpt_tvs = [TyCoVar]
ex_tvs'
, cpt_dicts :: [TyCoVar]
cpt_dicts = [TyCoVar]
prov_dicts'
, cpt_binds :: TcEvBinds
cpt_binds = TcEvBinds
ev_binds
, cpt_arg_tys :: [Type]
cpt_arg_tys = [TyCoVar] -> [Type]
mkTyVarTys [TyCoVar]
univ_tvs'
, cpt_wrap :: HsWrapper
cpt_wrap = HsWrapper
req_wrap
}
}
; Type
pat_ty <- ExpSigmaTypeFRR -> TcM Type
forall (m :: * -> *). MonadIO m => ExpSigmaTypeFRR -> m Type
readExpType (Scaled ExpSigmaTypeFRR -> ExpSigmaTypeFRR
forall a. Scaled a -> a
scaledThing Scaled ExpSigmaTypeFRR
pat_ty)
; (Pat GhcTc, r) -> TcM (Pat GhcTc, r)
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return (HsWrapper -> Pat GhcTc -> Type -> Pat GhcTc
mkHsWrapPat (HsWrapper
wrap HsWrapper -> HsWrapper -> HsWrapper
<.> HsWrapper
mult_wrap) Pat GhcTc
res_pat Type
pat_ty, r
res) }
checkFixedRuntimeRep :: DataCon -> [Scaled TcSigmaTypeFRR] -> TcM ()
checkFixedRuntimeRep :: DataCon -> [Scaled Type] -> TcRn ()
checkFixedRuntimeRep DataCon
data_con [Scaled Type]
arg_tys
= (Int -> Scaled Type -> TcRn ())
-> [Int] -> [Scaled Type] -> TcRn ()
forall (m :: * -> *) a b c.
Applicative m =>
(a -> b -> m c) -> [a] -> [b] -> m ()
zipWithM_ Int -> Scaled Type -> TcRn ()
check_one [Int
1..] [Scaled Type]
arg_tys
where
check_one :: Int -> Scaled Type -> TcRn ()
check_one Int
i Scaled Type
arg_ty = HasDebugCallStack => FixedRuntimeRepContext -> Type -> TcRn ()
FixedRuntimeRepContext -> Type -> TcRn ()
hasFixedRuntimeRep_syntactic
(DataCon -> Int -> FixedRuntimeRepContext
FRRDataConPatArg DataCon
data_con Int
i)
(Scaled Type -> Type
forall a. Scaled a -> a
scaledThing Scaled Type
arg_ty)
matchExpectedPatTy :: (TcRhoType -> TcM (TcCoercionN, a))
-> PatEnv -> ExpSigmaTypeFRR -> TcM (HsWrapper, a)
matchExpectedPatTy :: forall a.
(Type -> TcM (TcCoercionN, a))
-> PatEnv -> ExpSigmaTypeFRR -> TcM (HsWrapper, a)
matchExpectedPatTy Type -> TcM (TcCoercionN, a)
inner_match (PE { pe_orig :: PatEnv -> CtOrigin
pe_orig = CtOrigin
orig }) ExpSigmaTypeFRR
pat_ty
= do { Type
pat_ty <- ExpSigmaTypeFRR -> TcM Type
expTypeToType ExpSigmaTypeFRR
pat_ty
; (HsWrapper
wrap, Type
pat_rho) <- CtOrigin -> Type -> TcM (HsWrapper, Type)
topInstantiate CtOrigin
orig Type
pat_ty
; (TcCoercionN
co, a
res) <- Type -> TcM (TcCoercionN, a)
inner_match Type
pat_rho
; String -> SDoc -> TcRn ()
traceTc String
"matchExpectedPatTy" (Type -> SDoc
forall a. Outputable a => a -> SDoc
ppr Type
pat_ty SDoc -> SDoc -> SDoc
forall doc. IsDoc doc => doc -> doc -> doc
$$ HsWrapper -> SDoc
forall a. Outputable a => a -> SDoc
ppr HsWrapper
wrap)
; (HsWrapper, a) -> TcM (HsWrapper, a)
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return (TcCoercionN -> HsWrapper
mkWpCastN (TcCoercionN -> TcCoercionN
mkSymCo TcCoercionN
co) HsWrapper -> HsWrapper -> HsWrapper
<.> HsWrapper
wrap, a
res) }
matchExpectedConTy :: PatEnv
-> TyCon
-> Scaled ExpSigmaTypeFRR
-> TcM (HsWrapper, [TcSigmaType])
matchExpectedConTy :: PatEnv
-> TyCon -> Scaled ExpSigmaTypeFRR -> TcM (HsWrapper, [Type])
matchExpectedConTy (PE { pe_orig :: PatEnv -> CtOrigin
pe_orig = CtOrigin
orig }) TyCon
data_tc Scaled ExpSigmaTypeFRR
exp_pat_ty
| Just (TyCon
fam_tc, [Type]
fam_args, CoAxiom Unbranched
co_tc) <- TyCon -> Maybe (TyCon, [Type], CoAxiom Unbranched)
tyConFamInstSig_maybe TyCon
data_tc
= do { Type
pat_ty <- ExpSigmaTypeFRR -> TcM Type
expTypeToType (Scaled ExpSigmaTypeFRR -> ExpSigmaTypeFRR
forall a. Scaled a -> a
scaledThing Scaled ExpSigmaTypeFRR
exp_pat_ty)
; (HsWrapper
wrap, Type
pat_rho) <- CtOrigin -> Type -> TcM (HsWrapper, Type)
topInstantiate CtOrigin
orig Type
pat_ty
; (Subst
subst, [TyCoVar]
tvs') <- [TyCoVar] -> TcM (Subst, [TyCoVar])
newMetaTyVars (TyCon -> [TyCoVar]
tyConTyVars TyCon
data_tc)
; String -> SDoc -> TcRn ()
traceTc String
"matchExpectedConTy" ([SDoc] -> SDoc
forall doc. IsDoc doc => [doc] -> doc
vcat [TyCon -> SDoc
forall a. Outputable a => a -> SDoc
ppr TyCon
data_tc,
[TyCoVar] -> SDoc
forall a. Outputable a => a -> SDoc
ppr (TyCon -> [TyCoVar]
tyConTyVars TyCon
data_tc),
TyCon -> SDoc
forall a. Outputable a => a -> SDoc
ppr TyCon
fam_tc, [Type] -> SDoc
forall a. Outputable a => a -> SDoc
ppr [Type]
fam_args,
Scaled ExpSigmaTypeFRR -> SDoc
forall a. Outputable a => a -> SDoc
ppr Scaled ExpSigmaTypeFRR
exp_pat_ty,
Type -> SDoc
forall a. Outputable a => a -> SDoc
ppr Type
pat_ty,
Type -> SDoc
forall a. Outputable a => a -> SDoc
ppr Type
pat_rho, HsWrapper -> SDoc
forall a. Outputable a => a -> SDoc
ppr HsWrapper
wrap])
; TcCoercionN
co1 <- Maybe TypedThing -> Type -> Type -> TcM TcCoercionN
unifyType Maybe TypedThing
forall a. Maybe a
Nothing (TyCon -> [Type] -> Type
mkTyConApp TyCon
fam_tc (HasDebugCallStack => Subst -> [Type] -> [Type]
Subst -> [Type] -> [Type]
substTys Subst
subst [Type]
fam_args)) Type
pat_rho
; let tys' :: [Type]
tys' = [TyCoVar] -> [Type]
mkTyVarTys [TyCoVar]
tvs'
co2 :: TcCoercionN
co2 = Role
-> CoAxiom Unbranched -> [Type] -> [TcCoercionN] -> TcCoercionN
mkUnbranchedAxInstCo Role
Representational CoAxiom Unbranched
co_tc [Type]
tys' []
full_co :: TcCoercionN
full_co = HasDebugCallStack => TcCoercionN -> TcCoercionN
TcCoercionN -> TcCoercionN
mkSubCo (TcCoercionN -> TcCoercionN
mkSymCo TcCoercionN
co1) TcCoercionN -> TcCoercionN -> TcCoercionN
`mkTransCo` TcCoercionN
co2
; (HsWrapper, [Type]) -> TcM (HsWrapper, [Type])
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return ( TcCoercionN -> HsWrapper
mkWpCastR TcCoercionN
full_co HsWrapper -> HsWrapper -> HsWrapper
<.> HsWrapper
wrap, [Type]
tys') }
| Bool
otherwise
= do { Type
pat_ty <- ExpSigmaTypeFRR -> TcM Type
expTypeToType (Scaled ExpSigmaTypeFRR -> ExpSigmaTypeFRR
forall a. Scaled a -> a
scaledThing Scaled ExpSigmaTypeFRR
exp_pat_ty)
; (HsWrapper
wrap, Type
pat_rho) <- CtOrigin -> Type -> TcM (HsWrapper, Type)
topInstantiate CtOrigin
orig Type
pat_ty
; (TcCoercionN
coi, [Type]
tys) <- TyCon -> Type -> TcM (TcCoercionN, [Type])
matchExpectedTyConApp TyCon
data_tc Type
pat_rho
; (HsWrapper, [Type]) -> TcM (HsWrapper, [Type])
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return (TcCoercionN -> HsWrapper
mkWpCastN (TcCoercionN -> TcCoercionN
mkSymCo TcCoercionN
coi) HsWrapper -> HsWrapper -> HsWrapper
<.> HsWrapper
wrap, [Type]
tys) }
tcConValArgs :: ConLike
-> [Scaled TcSigmaTypeFRR]
-> Checker (HsConPatDetails GhcRn) (HsConPatDetails GhcTc)
tcConValArgs :: ConLike
-> [Scaled Type]
-> Checker (HsConPatDetails GhcRn) (HsConPatDetails GhcTc)
tcConValArgs ConLike
con_like [Scaled Type]
arg_tys PatEnv
penv HsConPatDetails GhcRn
con_args TcM r
thing_inside = case HsConPatDetails GhcRn
con_args of
PrefixCon [HsConPatTyArg (NoGhcTc GhcRn)]
type_args [LPat GhcRn]
arg_pats -> do
{ Bool -> TcRnMessage -> TcRn ()
checkTc (Int
con_arity Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
no_of_args)
(TyThing -> Int -> Int -> TcRnMessage
TcRnArityMismatch (ConLike -> TyThing
AConLike ConLike
con_like) Int
con_arity Int
no_of_args)
; let pats_w_tys :: [(GenLocated SrcSpanAnnA (Pat GhcRn), Scaled Type)]
pats_w_tys = String
-> [GenLocated SrcSpanAnnA (Pat GhcRn)]
-> [Scaled Type]
-> [(GenLocated SrcSpanAnnA (Pat GhcRn), Scaled Type)]
forall a b. HasDebugCallStack => String -> [a] -> [b] -> [(a, b)]
zipEqual String
"tcConArgs" [LPat GhcRn]
[GenLocated SrcSpanAnnA (Pat GhcRn)]
arg_pats [Scaled Type]
arg_tys
; ([GenLocated SrcSpanAnnA (Pat GhcTc)]
arg_pats', r
res) <- Checker
(GenLocated SrcSpanAnnA (Pat GhcRn), Scaled Type)
(GenLocated SrcSpanAnnA (Pat GhcTc))
-> Checker
[(GenLocated SrcSpanAnnA (Pat GhcRn), Scaled Type)]
[GenLocated SrcSpanAnnA (Pat GhcTc)]
forall inp out. Checker inp out -> Checker [inp] [out]
tcMultiple PatEnv -> (LPat GhcRn, Scaled Type) -> TcM r -> TcM (LPat GhcTc, r)
PatEnv
-> (GenLocated SrcSpanAnnA (Pat GhcRn), Scaled Type)
-> TcM r
-> IOEnv
(Env TcGblEnv TcLclEnv) (GenLocated SrcSpanAnnA (Pat GhcTc), r)
Checker (LPat GhcRn, Scaled Type) (LPat GhcTc)
Checker
(GenLocated SrcSpanAnnA (Pat GhcRn), Scaled Type)
(GenLocated SrcSpanAnnA (Pat GhcTc))
tcConArg PatEnv
penv [(GenLocated SrcSpanAnnA (Pat GhcRn), Scaled Type)]
pats_w_tys TcM r
thing_inside
; (HsConDetails
(HsConPatTyArg GhcRn)
(GenLocated SrcSpanAnnA (Pat GhcTc))
(HsRecFields GhcTc (GenLocated SrcSpanAnnA (Pat GhcTc))),
r)
-> IOEnv
(Env TcGblEnv TcLclEnv)
(HsConDetails
(HsConPatTyArg GhcRn)
(GenLocated SrcSpanAnnA (Pat GhcTc))
(HsRecFields GhcTc (GenLocated SrcSpanAnnA (Pat GhcTc))),
r)
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return ([HsConPatTyArg GhcRn]
-> [GenLocated SrcSpanAnnA (Pat GhcTc)]
-> HsConDetails
(HsConPatTyArg GhcRn)
(GenLocated SrcSpanAnnA (Pat GhcTc))
(HsRecFields GhcTc (GenLocated SrcSpanAnnA (Pat GhcTc)))
forall tyarg arg rec.
[tyarg] -> [arg] -> HsConDetails tyarg arg rec
PrefixCon [HsConPatTyArg (NoGhcTc GhcRn)]
[HsConPatTyArg 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 a. [a] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [LPat GhcRn]
[GenLocated SrcSpanAnnA (Pat GhcRn)]
arg_pats
InfixCon LPat GhcRn
p1 LPat GhcRn
p2 -> do
{ Bool -> TcRnMessage -> TcRn ()
checkTc (Int
con_arity Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
2)
(TyThing -> Int -> Int -> TcRnMessage
TcRnArityMismatch (ConLike -> TyThing
AConLike ConLike
con_like) Int
con_arity Int
2)
; let [Scaled Type
arg_ty1,Scaled Type
arg_ty2] = [Scaled Type]
arg_tys
; ([GenLocated SrcSpanAnnA (Pat GhcTc)
p1',GenLocated SrcSpanAnnA (Pat GhcTc)
p2'], r
res) <- Checker
(GenLocated SrcSpanAnnA (Pat GhcRn), Scaled Type)
(GenLocated SrcSpanAnnA (Pat GhcTc))
-> Checker
[(GenLocated SrcSpanAnnA (Pat GhcRn), Scaled Type)]
[GenLocated SrcSpanAnnA (Pat GhcTc)]
forall inp out. Checker inp out -> Checker [inp] [out]
tcMultiple PatEnv -> (LPat GhcRn, Scaled Type) -> TcM r -> TcM (LPat GhcTc, r)
PatEnv
-> (GenLocated SrcSpanAnnA (Pat GhcRn), Scaled Type)
-> TcM r
-> IOEnv
(Env TcGblEnv TcLclEnv) (GenLocated SrcSpanAnnA (Pat GhcTc), r)
Checker (LPat GhcRn, Scaled Type) (LPat GhcTc)
Checker
(GenLocated SrcSpanAnnA (Pat GhcRn), Scaled Type)
(GenLocated SrcSpanAnnA (Pat GhcTc))
tcConArg PatEnv
penv [(LPat GhcRn
GenLocated SrcSpanAnnA (Pat GhcRn)
p1,Scaled Type
arg_ty1),(LPat GhcRn
GenLocated SrcSpanAnnA (Pat GhcRn)
p2,Scaled Type
arg_ty2)]
TcM r
thing_inside
; (HsConDetails
(HsConPatTyArg GhcRn)
(GenLocated SrcSpanAnnA (Pat GhcTc))
(HsRecFields GhcTc (GenLocated SrcSpanAnnA (Pat GhcTc))),
r)
-> IOEnv
(Env TcGblEnv TcLclEnv)
(HsConDetails
(HsConPatTyArg GhcRn)
(GenLocated SrcSpanAnnA (Pat GhcTc))
(HsRecFields GhcTc (GenLocated SrcSpanAnnA (Pat GhcTc))),
r)
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return (GenLocated SrcSpanAnnA (Pat GhcTc)
-> GenLocated SrcSpanAnnA (Pat GhcTc)
-> HsConDetails
(HsConPatTyArg 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 (XRec GhcRn RecFieldsDotDot)
dd) -> do
{ ([GenLocated
SrcSpanAnnA
(HsFieldBind
(GenLocated (SrcAnn NoEpAnns) (FieldOcc GhcTc))
(GenLocated SrcSpanAnnA (Pat GhcTc)))]
rpats', r
res) <- Checker
(GenLocated
SrcSpanAnnA
(HsFieldBind
(GenLocated (SrcAnn NoEpAnns) (FieldOcc GhcRn))
(GenLocated SrcSpanAnnA (Pat GhcRn))))
(GenLocated
SrcSpanAnnA
(HsFieldBind
(GenLocated (SrcAnn NoEpAnns) (FieldOcc GhcTc))
(GenLocated SrcSpanAnnA (Pat GhcTc))))
-> Checker
[GenLocated
SrcSpanAnnA
(HsFieldBind
(GenLocated (SrcAnn NoEpAnns) (FieldOcc GhcRn))
(GenLocated SrcSpanAnnA (Pat GhcRn)))]
[GenLocated
SrcSpanAnnA
(HsFieldBind
(GenLocated (SrcAnn NoEpAnns) (FieldOcc GhcTc))
(GenLocated SrcSpanAnnA (Pat GhcTc)))]
forall inp out. Checker inp out -> Checker [inp] [out]
tcMultiple PatEnv
-> LHsRecField GhcRn (LPat GhcRn)
-> TcM r
-> TcM (LHsRecField GhcTc (LPat GhcTc), r)
PatEnv
-> GenLocated
SrcSpanAnnA
(HsFieldBind
(GenLocated (SrcAnn NoEpAnns) (FieldOcc GhcRn))
(GenLocated SrcSpanAnnA (Pat GhcRn)))
-> TcM r
-> IOEnv
(Env TcGblEnv TcLclEnv)
(GenLocated
SrcSpanAnnA
(HsFieldBind
(GenLocated (SrcAnn NoEpAnns) (FieldOcc GhcTc))
(GenLocated SrcSpanAnnA (Pat GhcTc))),
r)
Checker
(LHsRecField GhcRn (LPat GhcRn)) (LHsRecField GhcTc (LPat GhcTc))
Checker
(GenLocated
SrcSpanAnnA
(HsFieldBind
(GenLocated (SrcAnn NoEpAnns) (FieldOcc GhcRn))
(GenLocated SrcSpanAnnA (Pat GhcRn))))
(GenLocated
SrcSpanAnnA
(HsFieldBind
(GenLocated (SrcAnn NoEpAnns) (FieldOcc GhcTc))
(GenLocated SrcSpanAnnA (Pat GhcTc))))
tc_field PatEnv
penv [LHsRecField GhcRn (LPat GhcRn)]
[GenLocated
SrcSpanAnnA
(HsFieldBind
(GenLocated (SrcAnn NoEpAnns) (FieldOcc GhcRn))
(GenLocated SrcSpanAnnA (Pat GhcRn)))]
rpats TcM r
thing_inside
; (HsConDetails
(HsConPatTyArg GhcRn)
(GenLocated SrcSpanAnnA (Pat GhcTc))
(HsRecFields GhcTc (GenLocated SrcSpanAnnA (Pat GhcTc))),
r)
-> IOEnv
(Env TcGblEnv TcLclEnv)
(HsConDetails
(HsConPatTyArg GhcRn)
(GenLocated SrcSpanAnnA (Pat GhcTc))
(HsRecFields GhcTc (GenLocated SrcSpanAnnA (Pat GhcTc))),
r)
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return (HsRecFields GhcTc (GenLocated SrcSpanAnnA (Pat GhcTc))
-> HsConDetails
(HsConPatTyArg 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 (XRec GhcTc RecFieldsDotDot)
-> HsRecFields GhcTc (GenLocated SrcSpanAnnA (Pat GhcTc))
forall p arg.
[LHsRecField p arg]
-> Maybe (XRec p RecFieldsDotDot) -> HsRecFields p arg
HsRecFields [LHsRecField GhcTc (GenLocated SrcSpanAnnA (Pat GhcTc))]
[GenLocated
SrcSpanAnnA
(HsFieldBind
(GenLocated (SrcAnn NoEpAnns) (FieldOcc GhcTc))
(GenLocated SrcSpanAnnA (Pat GhcTc)))]
rpats' Maybe (XRec GhcRn RecFieldsDotDot)
Maybe (XRec GhcTc RecFieldsDotDot)
dd), r
res) }
where
tc_field :: Checker (LHsRecField GhcRn (LPat GhcRn))
(LHsRecField GhcTc (LPat GhcTc))
tc_field :: Checker
(LHsRecField GhcRn (LPat GhcRn)) (LHsRecField GhcTc (LPat GhcTc))
tc_field PatEnv
penv
(L SrcSpanAnnA
l (HsFieldBind XHsFieldBind (GenLocated (SrcAnn NoEpAnns) (FieldOcc GhcRn))
ann (L SrcAnn NoEpAnns
loc (FieldOcc XCFieldOcc GhcRn
sel (L SrcSpanAnnN
lr RdrName
rdr))) GenLocated SrcSpanAnnA (Pat GhcRn)
pat Bool
pun))
TcM r
thing_inside
= do { TyCoVar
sel' <- Name -> TcM TyCoVar
tcLookupId XCFieldOcc GhcRn
Name
sel
; Scaled Type
pat_ty <- SrcAnn NoEpAnns -> TcRn (Scaled Type) -> TcRn (Scaled Type)
forall ann a. SrcSpanAnn' ann -> TcRn a -> TcRn a
setSrcSpanA SrcAnn NoEpAnns
loc (TcRn (Scaled Type) -> TcRn (Scaled Type))
-> TcRn (Scaled Type) -> TcRn (Scaled Type)
forall a b. (a -> b) -> a -> b
$ Name -> FastString -> TcRn (Scaled Type)
find_field_ty XCFieldOcc GhcRn
Name
sel
(OccName -> FastString
occNameFS (OccName -> FastString) -> OccName -> FastString
forall a b. (a -> b) -> a -> b
$ RdrName -> OccName
rdrNameOcc RdrName
rdr)
; (GenLocated SrcSpanAnnA (Pat GhcTc)
pat', r
res) <- PatEnv -> (LPat GhcRn, Scaled Type) -> TcM r -> TcM (LPat GhcTc, r)
Checker (LPat GhcRn, Scaled Type) (LPat GhcTc)
tcConArg PatEnv
penv (LPat GhcRn
GenLocated SrcSpanAnnA (Pat GhcRn)
pat, Scaled Type
pat_ty) TcM r
thing_inside
; (GenLocated
SrcSpanAnnA
(HsFieldBind
(GenLocated (SrcAnn NoEpAnns) (FieldOcc GhcTc))
(GenLocated SrcSpanAnnA (Pat GhcTc))),
r)
-> IOEnv
(Env TcGblEnv TcLclEnv)
(GenLocated
SrcSpanAnnA
(HsFieldBind
(GenLocated (SrcAnn NoEpAnns) (FieldOcc GhcTc))
(GenLocated SrcSpanAnnA (Pat GhcTc))),
r)
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return (SrcSpanAnnA
-> HsFieldBind
(GenLocated (SrcAnn NoEpAnns) (FieldOcc GhcTc))
(GenLocated SrcSpanAnnA (Pat GhcTc))
-> GenLocated
SrcSpanAnnA
(HsFieldBind
(GenLocated (SrcAnn NoEpAnns) (FieldOcc GhcTc))
(GenLocated SrcSpanAnnA (Pat GhcTc)))
forall l e. l -> e -> GenLocated l e
L SrcSpanAnnA
l (XHsFieldBind (GenLocated (SrcAnn NoEpAnns) (FieldOcc GhcTc))
-> GenLocated (SrcAnn NoEpAnns) (FieldOcc GhcTc)
-> GenLocated SrcSpanAnnA (Pat GhcTc)
-> Bool
-> HsFieldBind
(GenLocated (SrcAnn NoEpAnns) (FieldOcc GhcTc))
(GenLocated SrcSpanAnnA (Pat GhcTc))
forall lhs rhs.
XHsFieldBind lhs -> lhs -> rhs -> Bool -> HsFieldBind lhs rhs
HsFieldBind XHsFieldBind (GenLocated (SrcAnn NoEpAnns) (FieldOcc GhcRn))
XHsFieldBind (GenLocated (SrcAnn NoEpAnns) (FieldOcc GhcTc))
ann (SrcAnn NoEpAnns
-> FieldOcc GhcTc -> GenLocated (SrcAnn NoEpAnns) (FieldOcc GhcTc)
forall l e. l -> e -> GenLocated l e
L SrcAnn NoEpAnns
loc (XCFieldOcc GhcTc -> XRec GhcTc RdrName -> FieldOcc GhcTc
forall pass. XCFieldOcc pass -> XRec pass RdrName -> FieldOcc pass
FieldOcc XCFieldOcc GhcTc
TyCoVar
sel' (SrcSpanAnnN -> RdrName -> GenLocated SrcSpanAnnN 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 -> FastString -> TcM (Scaled TcType)
find_field_ty :: Name -> FastString -> TcRn (Scaled Type)
find_field_ty Name
sel FastString
lbl
= case [Scaled Type
ty | (FieldLabel
fl, Scaled Type
ty) <- [(FieldLabel, Scaled Type)]
field_tys, FieldLabel -> Name
flSelector FieldLabel
fl Name -> Name -> Bool
forall a. Eq a => a -> a -> Bool
== Name
sel ] of
[] -> TcRnMessage -> TcRn (Scaled Type)
forall a. TcRnMessage -> TcRn a
failWith (Name -> FieldLabelString -> TcRnMessage
badFieldConErr (ConLike -> Name
forall a. NamedThing a => a -> Name
getName ConLike
con_like) (FastString -> FieldLabelString
FieldLabelString FastString
lbl))
(Scaled Type
pat_ty : [Scaled Type]
extras) -> do
String -> SDoc -> TcRn ()
traceTc String
"find_field" (Scaled Type -> SDoc
forall a. Outputable a => a -> SDoc
ppr Scaled Type
pat_ty SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> [Scaled Type] -> SDoc
forall a. Outputable a => a -> SDoc
ppr [Scaled Type]
extras)
Bool -> TcRn (Scaled Type) -> TcRn (Scaled Type)
forall a. HasCallStack => Bool -> a -> a
assert ([Scaled Type] -> Bool
forall a. [a] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [Scaled Type]
extras) (Scaled Type -> TcRn (Scaled Type)
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return Scaled Type
pat_ty)
field_tys :: [(FieldLabel, Scaled TcType)]
field_tys :: [(FieldLabel, Scaled Type)]
field_tys = [FieldLabel] -> [Scaled Type] -> [(FieldLabel, Scaled Type)]
forall a b. [a] -> [b] -> [(a, b)]
zip (ConLike -> [FieldLabel]
conLikeFieldLabels ConLike
con_like) [Scaled Type]
arg_tys
splitConTyArgs :: ConLike -> HsConPatDetails GhcRn
-> TcM ( [(HsConPatTyArg GhcRn, TyVar)]
, [(HsConPatTyArg GhcRn, TyVar)] )
splitConTyArgs :: ConLike
-> HsConPatDetails GhcRn
-> TcM
([(HsConPatTyArg GhcRn, TyCoVar)],
[(HsConPatTyArg GhcRn, TyCoVar)])
splitConTyArgs ConLike
con_like (PrefixCon [HsConPatTyArg (NoGhcTc GhcRn)]
type_args [LPat GhcRn]
_)
= do { Bool -> TcRnMessage -> TcRn ()
checkTc ([HsConPatTyArg (NoGhcTc GhcRn)]
[HsConPatTyArg GhcRn]
type_args [HsConPatTyArg GhcRn] -> [TyCoVar] -> Bool
forall a b. [a] -> [b] -> Bool
`leLength` [TyCoVar]
con_spec_bndrs)
(ConLike -> Int -> Int -> TcRnMessage
TcRnTooManyTyArgsInConPattern ConLike
con_like
([TyCoVar] -> Int
forall a. [a] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [TyCoVar]
con_spec_bndrs) ([HsConPatTyArg GhcRn] -> Int
forall a. [a] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [HsConPatTyArg (NoGhcTc GhcRn)]
[HsConPatTyArg GhcRn]
type_args))
; if [TyCoVar] -> Bool
forall a. [a] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [TyCoVar]
ex_tvs
then ([(HsConPatTyArg GhcRn, TyCoVar)],
[(HsConPatTyArg GhcRn, TyCoVar)])
-> TcM
([(HsConPatTyArg GhcRn, TyCoVar)],
[(HsConPatTyArg GhcRn, TyCoVar)])
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return ([(HsConPatTyArg GhcRn, TyCoVar)]
bndr_ty_arg_prs, [])
else ([(HsConPatTyArg GhcRn, TyCoVar)],
[(HsConPatTyArg GhcRn, TyCoVar)])
-> TcM
([(HsConPatTyArg GhcRn, TyCoVar)],
[(HsConPatTyArg GhcRn, TyCoVar)])
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return (((HsConPatTyArg GhcRn, TyCoVar) -> Bool)
-> [(HsConPatTyArg GhcRn, TyCoVar)]
-> ([(HsConPatTyArg GhcRn, TyCoVar)],
[(HsConPatTyArg GhcRn, TyCoVar)])
forall a. (a -> Bool) -> [a] -> ([a], [a])
partition (HsConPatTyArg GhcRn, TyCoVar) -> Bool
is_universal [(HsConPatTyArg GhcRn, TyCoVar)]
bndr_ty_arg_prs) }
where
ex_tvs :: [TyCoVar]
ex_tvs = ConLike -> [TyCoVar]
conLikeExTyCoVars ConLike
con_like
con_spec_bndrs :: [TyCoVar]
con_spec_bndrs = [ TyCoVar
tv | Bndr TyCoVar
tv Specificity
SpecifiedSpec <- ConLike -> [VarBndr TyCoVar Specificity]
conLikeUserTyVarBinders ConLike
con_like ]
bndr_ty_arg_prs :: [(HsConPatTyArg GhcRn, TyCoVar)]
bndr_ty_arg_prs = [HsConPatTyArg (NoGhcTc GhcRn)]
[HsConPatTyArg GhcRn]
type_args [HsConPatTyArg GhcRn]
-> [TyCoVar] -> [(HsConPatTyArg GhcRn, TyCoVar)]
forall a b. [a] -> [b] -> [(a, b)]
`zip` [TyCoVar]
con_spec_bndrs
is_universal :: (HsConPatTyArg GhcRn, TyCoVar) -> Bool
is_universal (HsConPatTyArg GhcRn
_, TyCoVar
tv) = Bool -> Bool
not (TyCoVar
tv TyCoVar -> [TyCoVar] -> Bool
forall a. Eq a => a -> [a] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` [TyCoVar]
ex_tvs)
splitConTyArgs ConLike
_ (RecCon {}) = ([(HsConPatTyArg GhcRn, TyCoVar)],
[(HsConPatTyArg GhcRn, TyCoVar)])
-> TcM
([(HsConPatTyArg GhcRn, TyCoVar)],
[(HsConPatTyArg GhcRn, TyCoVar)])
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return ([], [])
splitConTyArgs ConLike
_ (InfixCon {}) = ([(HsConPatTyArg GhcRn, TyCoVar)],
[(HsConPatTyArg GhcRn, TyCoVar)])
-> TcM
([(HsConPatTyArg GhcRn, TyCoVar)],
[(HsConPatTyArg GhcRn, TyCoVar)])
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return ([], [])
tcConTyArgs :: Subst -> PatEnv -> [(HsConPatTyArg GhcRn, TyVar)]
-> TcM a -> TcM a
tcConTyArgs :: forall a.
Subst
-> PatEnv -> [(HsConPatTyArg GhcRn, TyCoVar)] -> TcM a -> TcM a
tcConTyArgs Subst
tenv PatEnv
penv [(HsConPatTyArg GhcRn, TyCoVar)]
prs TcM a
thing_inside
= Checker (HsConPatTyArg GhcRn, TyCoVar) ()
-> PatEnv -> [(HsConPatTyArg GhcRn, TyCoVar)] -> TcM a -> TcM a
forall inp r. Checker inp () -> PatEnv -> [inp] -> TcM r -> TcM r
tcMultiple_ (Subst -> Checker (HsConPatTyArg GhcRn, TyCoVar) ()
tcConTyArg Subst
tenv) PatEnv
penv [(HsConPatTyArg GhcRn, TyCoVar)]
prs TcM a
thing_inside
tcConTyArg :: Subst -> Checker (HsConPatTyArg GhcRn, TyVar) ()
tcConTyArg :: Subst -> Checker (HsConPatTyArg GhcRn, TyCoVar) ()
tcConTyArg Subst
tenv PatEnv
penv (HsConPatTyArg LHsToken "@" GhcRn
_ HsPatSigType GhcRn
rn_ty, TyCoVar
con_tv) TcM r
thing_inside
= do { ([(Name, TyCoVar)]
sig_wcs, [(Name, TyCoVar)]
sig_ibs, Type
arg_ty) <- UserTypeCtxt
-> HoleMode
-> HsPatSigType GhcRn
-> ContextKind
-> TcM ([(Name, TyCoVar)], [(Name, TyCoVar)], Type)
tcHsPatSigType UserTypeCtxt
TypeAppCtxt HoleMode
HM_TyAppPat HsPatSigType GhcRn
rn_ty ContextKind
AnyKind
; case [(Name, TyCoVar)] -> Maybe (NonEmpty (Name, TyCoVar))
forall a. [a] -> Maybe (NonEmpty a)
NE.nonEmpty [(Name, TyCoVar)]
sig_ibs of
Just NonEmpty (Name, TyCoVar)
sig_ibs_ne | PatEnv -> Bool
inPatBind PatEnv
penv ->
TcRnMessage -> TcRn ()
addErr (NonEmpty (Name, TyCoVar) -> TcRnMessage
TcRnCannotBindTyVarsInPatBind NonEmpty (Name, TyCoVar)
sig_ibs_ne)
Maybe (NonEmpty (Name, TyCoVar))
_ -> () -> TcRn ()
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (f :: * -> *) a. Applicative f => a -> f a
pure ()
; TcCoercionN
_ <- Maybe TypedThing -> Type -> Type -> TcM TcCoercionN
unifyType Maybe TypedThing
forall a. Maybe a
Nothing Type
arg_ty (Subst -> TyCoVar -> Type
substTyVar Subst
tenv TyCoVar
con_tv)
; r
result <- [(Name, TyCoVar)] -> TcM r -> TcM r
forall r. [(Name, TyCoVar)] -> TcM r -> TcM r
tcExtendNameTyVarEnv [(Name, TyCoVar)]
sig_wcs (TcM r -> TcM r) -> TcM r -> TcM r
forall a b. (a -> b) -> a -> b
$
[(Name, TyCoVar)] -> TcM r -> TcM r
forall r. [(Name, TyCoVar)] -> TcM r -> TcM r
tcExtendNameTyVarEnv [(Name, TyCoVar)]
sig_ibs (TcM r -> TcM r) -> TcM r -> TcM r
forall a b. (a -> b) -> a -> b
$
TcM r
thing_inside
; ((), r) -> TcM ((), r)
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return ((), r
result) }
tcConArg :: Checker (LPat GhcRn, Scaled TcSigmaType) (LPat GhcTc)
tcConArg :: Checker (LPat GhcRn, Scaled Type) (LPat GhcTc)
tcConArg PatEnv
penv (LPat GhcRn
arg_pat, Scaled Type
arg_mult Type
arg_ty)
= Scaled ExpSigmaTypeFRR -> Checker (LPat GhcRn) (LPat GhcTc)
tc_lpat (Type -> ExpSigmaTypeFRR -> Scaled ExpSigmaTypeFRR
forall a. Type -> a -> Scaled a
Scaled Type
arg_mult (Type -> ExpSigmaTypeFRR
mkCheckExpType Type
arg_ty)) PatEnv
penv LPat GhcRn
arg_pat
addDataConStupidTheta :: DataCon -> [TcType] -> TcM ()
addDataConStupidTheta :: DataCon -> [Type] -> TcRn ()
addDataConStupidTheta DataCon
data_con [Type]
inst_tys
| [Type] -> Bool
forall a. [a] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [Type]
stupid_theta = () -> TcRn ()
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return ()
| Bool
otherwise = CtOrigin -> [Type] -> TcRn ()
instStupidTheta CtOrigin
origin [Type]
inst_theta
where
origin :: CtOrigin
origin = Name -> CtOrigin
OccurrenceOf (DataCon -> Name
dataConName DataCon
data_con)
stupid_theta :: [Type]
stupid_theta = DataCon -> [Type]
dataConStupidTheta DataCon
data_con
univ_tvs :: [TyCoVar]
univ_tvs = DataCon -> [TyCoVar]
dataConUnivTyVars DataCon
data_con
tenv :: Subst
tenv = [TyCoVar] -> [Type] -> Subst
HasDebugCallStack => [TyCoVar] -> [Type] -> Subst
zipTvSubst [TyCoVar]
univ_tvs ([TyCoVar] -> [Type] -> [Type]
forall b a. [b] -> [a] -> [a]
takeList [TyCoVar]
univ_tvs [Type]
inst_tys)
inst_theta :: [Type]
inst_theta = HasDebugCallStack => Subst -> [Type] -> [Type]
Subst -> [Type] -> [Type]
substTheta Subst
tenv [Type]
stupid_theta
maybeWrapPatCtxt :: Pat GhcRn -> (TcM a -> TcM b) -> TcM a -> TcM b
maybeWrapPatCtxt :: forall a b. 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
forall doc. IsLine doc => String -> doc
text String
"In the pattern:") Int
2 (Pat GhcRn -> SDoc
forall a. Outputable a => a -> SDoc
ppr Pat GhcRn
pat)
checkGADT :: ConLike
-> [TyVar]
-> [Type]
-> PatEnv
-> TcM ()
checkGADT :: ConLike -> [TyCoVar] -> [Type] -> PatEnv -> TcRn ()
checkGADT ConLike
conlike [TyCoVar]
ex_tvs [Type]
arg_tys = \case
PE { pe_ctxt :: PatEnv -> PatCtxt
pe_ctxt = LetPat {} }
-> () -> TcRn ()
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return ()
PE { pe_ctxt :: PatEnv -> PatCtxt
pe_ctxt = LamPat (ArrowMatchCtxt {}) }
| Bool -> Bool
not (Bool -> Bool) -> Bool -> Bool
forall a b. (a -> b) -> a -> b
$ ConLike -> Bool
isVanillaConLike ConLike
conlike
-> TcRnMessage -> TcRn ()
forall a. TcRnMessage -> TcRn a
failWithTc TcRnMessage
TcRnArrowProcGADTPattern
PE { pe_lazy :: PatEnv -> Bool
pe_lazy = Bool
True }
| Bool
has_existentials
-> TcRnMessage -> TcRn ()
forall a. TcRnMessage -> TcRn a
failWithTc TcRnMessage
TcRnLazyGADTPattern
PatEnv
_ -> () -> TcRn ()
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return ()
where
has_existentials :: Bool
has_existentials :: Bool
has_existentials = (TyCoVar -> Bool) -> [TyCoVar] -> Bool
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
any (TyCoVar -> VarSet -> Bool
`elemVarSet` [Type] -> VarSet
tyCoVarsOfTypes [Type]
arg_tys) [TyCoVar]
ex_tvs