{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TupleSections #-}
{-# LANGUAGE TypeFamilies #-}
{-# OPTIONS_GHC -Wno-incomplete-uni-patterns #-}
module GHC.Tc.Gen.Pat
( tcLetPat
, newLetBndr
, LetBndrSpec(..)
, tcCheckPat, tcCheckPat_O, tcInferPat
, tcMatchPats
, 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 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 )
import Control.Monad.Trans.Writer.CPS
import Control.Monad.Trans.Class
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 { bind_lvl <- TcM TcLevel
getTcLevel
; let 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 = PE { pe_lazy :: Bool
pe_lazy = Bool
True
, pe_ctxt :: PatCtxt
pe_ctxt = PatCtxt
ctxt
, pe_orig :: CtOrigin
pe_orig = CtOrigin
PatOrigin }
; dflags <- getDynFlags
; manyIfLazy dflags pat
; tc_lpat pat_ty penv pat thing_inside }
where
manyIfLazy :: DynFlags -> GenLocated SrcSpanAnnA (Pat GhcRn) -> TcM ()
manyIfLazy DynFlags
dflags GenLocated SrcSpanAnnA (Pat GhcRn)
lpat
| Extension -> DynFlags -> Bool
xopt Extension
LangExt.Strict DynFlags
dflags = GenLocated SrcSpanAnnA (Pat GhcRn) -> TcM ()
xstrict GenLocated SrcSpanAnnA (Pat GhcRn)
lpat
| Bool
otherwise = GenLocated SrcSpanAnnA (Pat GhcRn) -> TcM ()
not_xstrict GenLocated SrcSpanAnnA (Pat GhcRn)
lpat
where
xstrict :: GenLocated SrcSpanAnnA (Pat GhcRn) -> TcM ()
xstrict p :: GenLocated SrcSpanAnnA (Pat GhcRn)
p@(L SrcSpanAnnA
_ (LazyPat XLazyPat GhcRn
_ LPat GhcRn
_)) = NonLinearPatternReason
-> LPat GhcRn -> Scaled ExpSigmaTypeFRR -> TcM ()
forall a.
NonLinearPatternReason -> LPat GhcRn -> Scaled a -> TcM ()
checkManyPattern NonLinearPatternReason
LazyPatternReason LPat GhcRn
GenLocated SrcSpanAnnA (Pat GhcRn)
p Scaled ExpSigmaTypeFRR
pat_ty
xstrict (L SrcSpanAnnA
_ (ParPat XParPat GhcRn
_ LPat GhcRn
p)) = GenLocated SrcSpanAnnA (Pat GhcRn) -> TcM ()
xstrict LPat GhcRn
GenLocated SrcSpanAnnA (Pat GhcRn)
p
xstrict GenLocated SrcSpanAnnA (Pat GhcRn)
_ = () -> TcM ()
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return ()
not_xstrict :: GenLocated SrcSpanAnnA (Pat GhcRn) -> TcM ()
not_xstrict (L SrcSpanAnnA
_ (BangPat XBangPat GhcRn
_ LPat GhcRn
_)) = () -> TcM ()
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return ()
not_xstrict (L SrcSpanAnnA
_ (VarPat XVarPat GhcRn
_ LIdP GhcRn
_)) = () -> TcM ()
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return ()
not_xstrict (L SrcSpanAnnA
_ (ParPat XParPat GhcRn
_ LPat GhcRn
p)) = GenLocated SrcSpanAnnA (Pat GhcRn) -> TcM ()
not_xstrict LPat GhcRn
GenLocated SrcSpanAnnA (Pat GhcRn)
p
not_xstrict GenLocated SrcSpanAnnA (Pat GhcRn)
p = NonLinearPatternReason
-> LPat GhcRn -> Scaled ExpSigmaTypeFRR -> TcM ()
forall a.
NonLinearPatternReason -> LPat GhcRn -> Scaled a -> TcM ()
checkManyPattern NonLinearPatternReason
LazyPatternReason LPat GhcRn
GenLocated SrcSpanAnnA (Pat GhcRn)
p Scaled ExpSigmaTypeFRR
pat_ty
tcMatchPats :: forall a.
HsMatchContextRn
-> [LPat GhcRn]
-> [ExpPatType]
-> TcM a
-> TcM ([LPat GhcTc], a)
tcMatchPats :: forall a.
HsMatchContextRn
-> [LPat GhcRn] -> [ExpPatType] -> TcM a -> TcM ([LPat GhcTc], a)
tcMatchPats HsMatchContextRn
match_ctxt [LPat GhcRn]
pats [ExpPatType]
pat_tys TcM a
thing_inside
= Bool -> SDoc -> TcM ([LPat GhcTc], a) -> TcM ([LPat GhcTc], a)
forall a. HasCallStack => Bool -> SDoc -> a -> a
assertPpr ((ExpPatType -> Bool) -> [ExpPatType] -> Int
forall a. (a -> Bool) -> [a] -> Int
count ExpPatType -> Bool
isVisibleExpPatType [ExpPatType]
pat_tys Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== (GenLocated SrcSpanAnnA (Pat GhcRn) -> Bool)
-> [GenLocated SrcSpanAnnA (Pat GhcRn)] -> Int
forall a. (a -> Bool) -> [a] -> Int
count (Pat GhcRn -> Bool
forall p. Pat p -> Bool
isVisArgPat (Pat GhcRn -> Bool)
-> (GenLocated SrcSpanAnnA (Pat GhcRn) -> Pat GhcRn)
-> GenLocated SrcSpanAnnA (Pat GhcRn)
-> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. GenLocated SrcSpanAnnA (Pat GhcRn) -> Pat GhcRn
forall l e. GenLocated l e -> e
unLoc) [LPat GhcRn]
[GenLocated SrcSpanAnnA (Pat GhcRn)]
pats)
([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
$$ [ExpPatType] -> SDoc
forall a. Outputable a => a -> SDoc
ppr [ExpPatType]
pat_tys) (TcM ([LPat GhcTc], a) -> TcM ([LPat GhcTc], a))
-> TcM ([LPat GhcTc], a) -> TcM ([LPat GhcTc], a)
forall a b. (a -> b) -> a -> b
$
do { err_ctxt <- TcM [ErrCtxt]
getErrCtxt
; let loop :: [LPat GhcRn] -> [ExpPatType] -> TcM ([LPat GhcTc], a)
loop [] [ExpPatType]
pat_tys
= Bool -> SDoc -> TcM ([LPat GhcTc], a) -> TcM ([LPat GhcTc], a)
forall a. HasCallStack => Bool -> SDoc -> a -> a
assertPpr (Bool -> Bool
not ((ExpPatType -> Bool) -> [ExpPatType] -> Bool
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
any ExpPatType -> Bool
isVisibleExpPatType [ExpPatType]
pat_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
$$ [ExpPatType] -> SDoc
forall a. Outputable a => a -> SDoc
ppr [ExpPatType]
pat_tys) (TcM ([LPat GhcTc], a) -> TcM ([LPat GhcTc], a))
-> TcM ([LPat GhcTc], a) -> TcM ([LPat GhcTc], a)
forall a b. (a -> b) -> a -> b
$
do { res <- [ErrCtxt] -> TcM a -> TcM a
forall a. [ErrCtxt] -> TcM a -> TcM a
setErrCtxt [ErrCtxt]
err_ctxt TcM a
thing_inside
; return ([], res) }
loop all_pats :: [LPat GhcRn]
all_pats@(LPat GhcRn
pat : [LPat GhcRn]
pats) (ExpForAllPatTy (Bndr TyCoVar
tv ForAllTyFlag
vis) : [ExpPatType]
pat_tys)
| ForAllTyFlag -> Bool
isVisibleForAllTyFlag ForAllTyFlag
vis
= do { (_p, (ps, res)) <- TyCoVar -> Checker (LPat GhcRn) (LPat GhcTc)
tc_forall_lpat TyCoVar
tv PatEnv
penv LPat GhcRn
pat (TcM ([LPat GhcTc], a) -> TcM (LPat GhcTc, ([LPat GhcTc], a)))
-> TcM ([LPat GhcTc], a) -> TcM (LPat GhcTc, ([LPat GhcTc], a))
forall a b. (a -> b) -> a -> b
$
[LPat GhcRn] -> [ExpPatType] -> TcM ([LPat GhcTc], a)
loop [LPat GhcRn]
pats [ExpPatType]
pat_tys
; return (ps, res) }
| L SrcSpanAnnA
_ (InvisPat XInvisPat GhcRn
pat_spec HsTyPat (NoGhcTc GhcRn)
tp) <- LPat GhcRn
pat
, Invisible Specificity
spec <- ForAllTyFlag
vis
, XInvisPat GhcRn
Specificity
pat_spec Specificity -> Specificity -> Bool
forall a. Eq a => a -> a -> Bool
== Specificity
spec
= do { (_p, (ps, res)) <- HsTyPat GhcRn
-> TyCoVar
-> TcM ([LPat GhcTc], a)
-> TcM (Type, ([LPat GhcTc], a))
forall r. HsTyPat GhcRn -> TyCoVar -> TcM r -> TcM (Type, r)
tc_ty_pat HsTyPat (NoGhcTc GhcRn)
HsTyPat GhcRn
tp TyCoVar
tv (TcM ([LPat GhcTc], a) -> TcM (Type, ([LPat GhcTc], a)))
-> TcM ([LPat GhcTc], a) -> TcM (Type, ([LPat GhcTc], a))
forall a b. (a -> b) -> a -> b
$
[LPat GhcRn] -> [ExpPatType] -> TcM ([LPat GhcTc], a)
loop [LPat GhcRn]
pats [ExpPatType]
pat_tys
; return (ps, res) }
| Bool
otherwise
= [LPat GhcRn] -> [ExpPatType] -> TcM ([LPat GhcTc], a)
loop [LPat GhcRn]
all_pats [ExpPatType]
pat_tys
loop (L SrcSpanAnnA
loc (InvisPat XInvisPat GhcRn
_ HsTyPat (NoGhcTc GhcRn)
tp) : [LPat GhcRn]
_) [ExpPatType]
_ =
SrcSpan
-> TcRnMessage
-> IOEnv
(Env TcGblEnv TcLclEnv) ([GenLocated SrcSpanAnnA (Pat GhcTc)], a)
forall a. SrcSpan -> TcRnMessage -> TcRn a
failAt (SrcSpanAnnA -> SrcSpan
forall a. HasLoc a => a -> SrcSpan
locA SrcSpanAnnA
loc) (HsTyPat GhcRn -> TcRnMessage
TcRnInvisPatWithNoForAll HsTyPat (NoGhcTc GhcRn)
HsTyPat GhcRn
tp)
loop (LPat GhcRn
pat : [LPat GhcRn]
pats) (ExpFunPatTy Scaled ExpSigmaTypeFRR
pat_ty : [ExpPatType]
pat_tys)
= do { (p, (ps, res)) <- Scaled ExpSigmaTypeFRR -> Checker (LPat GhcRn) (LPat GhcTc)
tc_lpat Scaled ExpSigmaTypeFRR
pat_ty PatEnv
penv LPat GhcRn
pat (TcM ([LPat GhcTc], a) -> TcM (LPat GhcTc, ([LPat GhcTc], a)))
-> TcM ([LPat GhcTc], a) -> TcM (LPat GhcTc, ([LPat GhcTc], a))
forall a b. (a -> b) -> a -> b
$
[LPat GhcRn] -> [ExpPatType] -> TcM ([LPat GhcTc], a)
loop [LPat GhcRn]
pats [ExpPatType]
pat_tys
; return (p : ps, res) }
loop pats :: [LPat GhcRn]
pats@(LPat GhcRn
_:[LPat GhcRn]
_) [] = String
-> SDoc
-> IOEnv
(Env TcGblEnv TcLclEnv) ([GenLocated SrcSpanAnnA (Pat GhcTc)], a)
forall a. HasCallStack => String -> SDoc -> a
pprPanic String
"tcMatchPats" ([GenLocated SrcSpanAnnA (Pat GhcRn)] -> SDoc
forall a. Outputable a => a -> SDoc
ppr [LPat GhcRn]
[GenLocated SrcSpanAnnA (Pat GhcRn)]
pats)
; loop pats pat_tys }
where
penv :: PatEnv
penv = PE { pe_lazy :: Bool
pe_lazy = Bool
False, pe_ctxt :: PatCtxt
pe_ctxt = HsMatchContextRn -> PatCtxt
LamPat HsMatchContextRn
match_ctxt, pe_orig :: CtOrigin
pe_orig = CtOrigin
PatOrigin }
tcInferPat :: FixedRuntimeRepContext
-> HsMatchContextRn
-> LPat GhcRn
-> TcM a
-> TcM ((LPat GhcTc, a), TcSigmaTypeFRR)
tcInferPat :: forall a.
FixedRuntimeRepContext
-> HsMatchContextRn
-> LPat GhcRn
-> TcM a
-> TcM ((LPat GhcTc, a), Type)
tcInferPat FixedRuntimeRepContext
frr_orig HsMatchContextRn
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 = HsMatchContextRn -> PatCtxt
LamPat HsMatchContextRn
ctxt, pe_orig :: CtOrigin
pe_orig = CtOrigin
PatOrigin }
tcCheckPat :: HsMatchContextRn
-> LPat GhcRn -> Scaled TcSigmaTypeFRR
-> TcM a
-> TcM (LPat GhcTc, a)
tcCheckPat :: forall a.
HsMatchContextRn
-> LPat GhcRn -> Scaled Type -> TcM a -> TcM (LPat GhcTc, a)
tcCheckPat HsMatchContextRn
ctxt = HsMatchContextRn
-> CtOrigin
-> LPat GhcRn
-> Scaled Type
-> TcM a
-> TcM (LPat GhcTc, a)
forall a.
HsMatchContextRn
-> CtOrigin
-> LPat GhcRn
-> Scaled Type
-> TcM a
-> TcM (LPat GhcTc, a)
tcCheckPat_O HsMatchContextRn
ctxt CtOrigin
PatOrigin
tcCheckPat_O :: HsMatchContextRn
-> CtOrigin
-> LPat GhcRn -> Scaled TcSigmaTypeFRR
-> TcM a
-> TcM (LPat GhcTc, a)
tcCheckPat_O :: forall a.
HsMatchContextRn
-> CtOrigin
-> LPat GhcRn
-> Scaled Type
-> TcM a
-> TcM (LPat GhcTc, a)
tcCheckPat_O HsMatchContextRn
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 = HsMatchContextRn -> PatCtxt
LamPat HsMatchContextRn
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
HsMatchContextRn
| 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 { 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)
; traceTc "tcPatBndr(sig)" (ppr bndr_id $$ ppr (idType bndr_id) $$ ppr exp_pat_ty)
; return (wrap, bndr_id) }
| Bool
otherwise
= do { (co, 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
`sameDepthAs` 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 { bndr_ty <- InferResult -> TcM Type
inferResultToType InferResult
infer_res
; return (mkNomReflCo bndr_ty, bndr_ty) }
; let bndr_mult = Scaled ExpSigmaTypeFRR -> Type
forall a. Scaled a -> Type
scaledMult Scaled ExpSigmaTypeFRR
exp_pat_ty
; bndr_id <- newLetBndr no_gen bndr_name bndr_mult bndr_ty
; traceTc "tcPatBndr(nosig)" (vcat [ ppr bind_lvl
, ppr exp_pat_ty, ppr bndr_ty, ppr co
, ppr bndr_id ])
; return (mkWpCastN co, 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
; pat_ty <- ExpSigmaTypeFRR -> TcM Type
expTypeToType (Scaled ExpSigmaTypeFRR -> ExpSigmaTypeFRR
forall a. Scaled a -> a
scaledThing Scaled ExpSigmaTypeFRR
pat_ty)
; traceTc "tcPatBndr(not let)" (ppr bndr_name $$ ppr pat_ty)
; return (idHsWrapper, mkLocalIdOrCoVar bndr_name pat_mult 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 { mono_name <- Name -> TcM Name
cloneLocalName Name
name
; return (mkLocalId mono_name w 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 { (_, 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
; return 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 { err_ctxt <- TcM [ErrCtxt]
getErrCtxt
; let loop []
= do { res <- TcM r
thing_inside
; return ([], res) }
loop (inp
arg:[inp]
args)
= do { (p', (ps', res))
<- PatEnv
-> inp
-> IOEnv (Env TcGblEnv TcLclEnv) ([out], r)
-> TcM (out, ([out], r))
Checker inp out
tc_pat PatEnv
penv inp
arg (IOEnv (Env TcGblEnv TcLclEnv) ([out], r) -> TcM (out, ([out], r)))
-> IOEnv (Env TcGblEnv TcLclEnv) ([out], r)
-> TcM (out, ([out], r))
forall a b. (a -> b) -> a -> b
$
[ErrCtxt]
-> IOEnv (Env TcGblEnv TcLclEnv) ([out], r)
-> IOEnv (Env TcGblEnv TcLclEnv) ([out], r)
forall a. [ErrCtxt] -> TcM a -> TcM a
setErrCtxt [ErrCtxt]
err_ctxt (IOEnv (Env TcGblEnv TcLclEnv) ([out], r)
-> IOEnv (Env TcGblEnv TcLclEnv) ([out], r))
-> IOEnv (Env TcGblEnv TcLclEnv) ([out], r)
-> IOEnv (Env TcGblEnv TcLclEnv) ([out], r)
forall a b. (a -> b) -> a -> b
$
[inp] -> IOEnv (Env TcGblEnv TcLclEnv) ([out], r)
loop [inp]
args
; return (p':ps', res) }
; loop 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. EpAnn 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', 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
; return (L span pat', 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)
(LPat GhcTc)
-> Checker
[(GenLocated SrcSpanAnnA (Pat GhcRn), Scaled ExpSigmaTypeFRR)]
[LPat 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 :: NonLinearPatternReason -> LPat GhcRn -> Scaled a -> TcM ()
checkManyPattern :: forall a.
NonLinearPatternReason -> LPat GhcRn -> Scaled a -> TcM ()
checkManyPattern NonLinearPatternReason
reason LPat GhcRn
pat Scaled a
pat_ty = CtOrigin -> Type -> Type -> TcM ()
tcSubMult (NonLinearPatternReason -> LPat GhcRn -> CtOrigin
NonLinearPatternOrigin NonLinearPatternReason
reason LPat GhcRn
pat) Type
ManyTy (Scaled a -> Type
forall a. Scaled a -> Type
scaledMult Scaled a
pat_ty)
tc_forall_lpat :: TcTyVar -> Checker (LPat GhcRn) (LPat GhcTc)
tc_forall_lpat :: TyCoVar -> Checker (LPat GhcRn) (LPat GhcTc)
tc_forall_lpat TyCoVar
tv PatEnv
penv (L SrcSpanAnnA
span Pat GhcRn
pat) TcM r
thing_inside
= SrcSpanAnnA -> TcRn (LPat GhcTc, r) -> TcRn (LPat GhcTc, r)
forall ann a. EpAnn 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', 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 (TyCoVar -> Checker (Pat GhcRn) (Pat GhcTc)
tc_forall_pat TyCoVar
tv PatEnv
penv Pat GhcRn
pat)
TcM r
thing_inside
; return (L span pat', res) }
tc_forall_pat :: TcTyVar -> Checker (Pat GhcRn) (Pat GhcTc)
tc_forall_pat :: TyCoVar -> Checker (Pat GhcRn) (Pat GhcTc)
tc_forall_pat TyCoVar
tv PatEnv
penv (ParPat XParPat GhcRn
x LPat GhcRn
lpat) TcM r
thing_inside
= do { (lpat', res) <- TyCoVar -> Checker (LPat GhcRn) (LPat GhcTc)
tc_forall_lpat TyCoVar
tv PatEnv
penv LPat GhcRn
lpat TcM r
thing_inside
; return (ParPat x lpat', res) }
tc_forall_pat TyCoVar
tv PatEnv
_ (EmbTyPat XEmbTyPat GhcRn
_ HsTyPat (NoGhcTc GhcRn)
tp) TcM r
thing_inside
= do { (arg_ty, result) <- HsTyPat GhcRn -> TyCoVar -> TcM r -> TcM (Type, r)
forall r. HsTyPat GhcRn -> TyCoVar -> TcM r -> TcM (Type, r)
tc_ty_pat HsTyPat (NoGhcTc GhcRn)
HsTyPat GhcRn
tp TyCoVar
tv TcM r
thing_inside
; return (EmbTyPat arg_ty tp, result) }
tc_forall_pat TyCoVar
tv PatEnv
_ Pat GhcRn
pat TcM r
thing_inside
= do { tp <- Pat GhcRn -> TcM (HsTyPat GhcRn)
pat_to_type_pat Pat GhcRn
pat
; (arg_ty, result) <- tc_ty_pat tp tv thing_inside
; let pat' = 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
pat (XEmbTyPat GhcTc -> HsTyPat (NoGhcTc GhcTc) -> Pat GhcTc
forall p. XEmbTyPat p -> HsTyPat (NoGhcTc p) -> Pat p
EmbTyPat XEmbTyPat GhcTc
Type
arg_ty HsTyPat (NoGhcTc GhcTc)
HsTyPat GhcRn
tp)
; return (pat', result) }
pat_to_type_pat :: Pat GhcRn -> TcM (HsTyPat GhcRn)
pat_to_type_pat :: Pat GhcRn -> TcM (HsTyPat GhcRn)
pat_to_type_pat Pat GhcRn
pat = do
(ty, x) <- WriterT
HsTyPatRnBuilder
(IOEnv (Env TcGblEnv TcLclEnv))
(GenLocated SrcSpanAnnA (HsType GhcRn))
-> IOEnv
(Env TcGblEnv TcLclEnv)
(GenLocated SrcSpanAnnA (HsType GhcRn), HsTyPatRnBuilder)
forall w (m :: * -> *) a. Monoid w => WriterT w m a -> m (a, w)
runWriterT (Pat GhcRn
-> WriterT
HsTyPatRnBuilder (IOEnv (Env TcGblEnv TcLclEnv)) (LHsType GhcRn)
pat_to_type Pat GhcRn
pat)
pure (HsTP (buildHsTyPatRn x) ty)
pat_to_type :: Pat GhcRn -> WriterT HsTyPatRnBuilder TcM (LHsType GhcRn)
pat_to_type :: Pat GhcRn
-> WriterT
HsTyPatRnBuilder (IOEnv (Env TcGblEnv TcLclEnv)) (LHsType GhcRn)
pat_to_type (EmbTyPat XEmbTyPat GhcRn
_ (HsTP XHsTP (NoGhcTc GhcRn)
x LHsType (NoGhcTc GhcRn)
t)) =
do { HsTyPatRnBuilder
-> WriterT HsTyPatRnBuilder (IOEnv (Env TcGblEnv TcLclEnv)) ()
forall w (m :: * -> *). (Monoid w, Monad m) => w -> WriterT w m ()
tell (HsTyPatRn -> HsTyPatRnBuilder
builderFromHsTyPatRn XHsTP (NoGhcTc GhcRn)
HsTyPatRn
x)
; GenLocated SrcSpanAnnA (HsType GhcRn)
-> WriterT
HsTyPatRnBuilder
(IOEnv (Env TcGblEnv TcLclEnv))
(GenLocated SrcSpanAnnA (HsType GhcRn))
forall a.
a -> WriterT HsTyPatRnBuilder (IOEnv (Env TcGblEnv TcLclEnv)) a
forall (m :: * -> *) a. Monad m => a -> m a
return LHsType (NoGhcTc GhcRn)
GenLocated SrcSpanAnnA (HsType GhcRn)
t }
pat_to_type (VarPat XVarPat GhcRn
_ LIdP GhcRn
lname) =
do { HsTyPatRnBuilder
-> WriterT HsTyPatRnBuilder (IOEnv (Env TcGblEnv TcLclEnv)) ()
forall w (m :: * -> *). (Monoid w, Monad m) => w -> WriterT w m ()
tell (Name -> HsTyPatRnBuilder
tpBuilderExplicitTV (GenLocated SrcSpanAnnN Name -> Name
forall l e. GenLocated l e -> e
unLoc LIdP GhcRn
GenLocated SrcSpanAnnN Name
lname))
; GenLocated SrcSpanAnnA (HsType GhcRn)
-> WriterT
HsTyPatRnBuilder
(IOEnv (Env TcGblEnv TcLclEnv))
(GenLocated SrcSpanAnnA (HsType GhcRn))
forall a.
a -> WriterT HsTyPatRnBuilder (IOEnv (Env TcGblEnv TcLclEnv)) a
forall (m :: * -> *) a. Monad m => a -> m a
return GenLocated SrcSpanAnnA (HsType GhcRn)
b }
where b :: GenLocated SrcSpanAnnA (HsType GhcRn)
b = HsType GhcRn -> GenLocated SrcSpanAnnA (HsType GhcRn)
forall e a. HasAnnotation e => a -> GenLocated e a
noLocA (XTyVar GhcRn -> PromotionFlag -> LIdP GhcRn -> HsType GhcRn
forall pass.
XTyVar pass -> PromotionFlag -> LIdP pass -> HsType pass
HsTyVar XTyVar GhcRn
forall a. NoAnn a => a
noAnn PromotionFlag
NotPromoted LIdP GhcRn
lname)
pat_to_type (WildPat XWildPat GhcRn
_) = GenLocated SrcSpanAnnA (HsType GhcRn)
-> WriterT
HsTyPatRnBuilder
(IOEnv (Env TcGblEnv TcLclEnv))
(GenLocated SrcSpanAnnA (HsType GhcRn))
forall a.
a -> WriterT HsTyPatRnBuilder (IOEnv (Env TcGblEnv TcLclEnv)) a
forall (m :: * -> *) a. Monad m => a -> m a
return GenLocated SrcSpanAnnA (HsType GhcRn)
b
where b :: GenLocated SrcSpanAnnA (HsType GhcRn)
b = HsType GhcRn -> GenLocated SrcSpanAnnA (HsType GhcRn)
forall e a. HasAnnotation e => a -> GenLocated e a
noLocA (XWildCardTy GhcRn -> HsType GhcRn
forall pass. XWildCardTy pass -> HsType pass
HsWildCardTy XWildCardTy GhcRn
NoExtField
noExtField)
pat_to_type (SigPat XSigPat GhcRn
_ LPat GhcRn
pat HsPatSigType (NoGhcTc GhcRn)
sig_ty)
= do { t <- Pat GhcRn
-> WriterT
HsTyPatRnBuilder (IOEnv (Env TcGblEnv TcLclEnv)) (LHsType GhcRn)
pat_to_type (GenLocated SrcSpanAnnA (Pat GhcRn) -> Pat GhcRn
forall l e. GenLocated l e -> e
unLoc LPat GhcRn
GenLocated SrcSpanAnnA (Pat GhcRn)
pat)
; let { !(HsPS x_hsps k) = sig_ty
; b = HsType GhcRn -> GenLocated SrcSpanAnnA (HsType GhcRn)
forall e a. HasAnnotation e => a -> GenLocated e a
noLocA (XKindSig GhcRn -> LHsType GhcRn -> LHsType GhcRn -> HsType GhcRn
forall pass.
XKindSig pass -> LHsType pass -> LHsType pass -> HsType pass
HsKindSig XKindSig GhcRn
TokDcolon
forall a. NoAnn a => a
noAnn LHsType GhcRn
GenLocated SrcSpanAnnA (HsType GhcRn)
t LHsType (NoGhcTc GhcRn)
LHsType GhcRn
k) }
; tell (tpBuilderPatSig x_hsps)
; return b }
pat_to_type (ParPat XParPat GhcRn
_ LPat GhcRn
pat)
= do { t <- Pat GhcRn
-> WriterT
HsTyPatRnBuilder (IOEnv (Env TcGblEnv TcLclEnv)) (LHsType GhcRn)
pat_to_type (GenLocated SrcSpanAnnA (Pat GhcRn) -> Pat GhcRn
forall l e. GenLocated l e -> e
unLoc LPat GhcRn
GenLocated SrcSpanAnnA (Pat GhcRn)
pat)
; return (noLocA (HsParTy noAnn t)) }
pat_to_type (SplicePat (HsUntypedSpliceTop ThModFinalizers
mod_finalizers Pat GhcRn
pat) HsUntypedSplice GhcRn
splice) = do
{ t <- Pat GhcRn
-> WriterT
HsTyPatRnBuilder (IOEnv (Env TcGblEnv TcLclEnv)) (LHsType GhcRn)
pat_to_type Pat GhcRn
pat
; return (noLocA (HsSpliceTy (HsUntypedSpliceTop mod_finalizers t) splice)) }
pat_to_type (TuplePat XTuplePat GhcRn
_ [LPat GhcRn]
pats Boxity
Boxed)
= do { tys <- (GenLocated SrcSpanAnnA (Pat GhcRn)
-> WriterT
HsTyPatRnBuilder
(IOEnv (Env TcGblEnv TcLclEnv))
(GenLocated SrcSpanAnnA (HsType GhcRn)))
-> [GenLocated SrcSpanAnnA (Pat GhcRn)]
-> WriterT
HsTyPatRnBuilder
(IOEnv (Env TcGblEnv TcLclEnv))
[GenLocated SrcSpanAnnA (HsType GhcRn)]
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> [a] -> f [b]
traverse (Pat GhcRn
-> WriterT
HsTyPatRnBuilder (IOEnv (Env TcGblEnv TcLclEnv)) (LHsType GhcRn)
Pat GhcRn
-> WriterT
HsTyPatRnBuilder
(IOEnv (Env TcGblEnv TcLclEnv))
(GenLocated SrcSpanAnnA (HsType GhcRn))
pat_to_type (Pat GhcRn
-> WriterT
HsTyPatRnBuilder
(IOEnv (Env TcGblEnv TcLclEnv))
(GenLocated SrcSpanAnnA (HsType GhcRn)))
-> (GenLocated SrcSpanAnnA (Pat GhcRn) -> Pat GhcRn)
-> GenLocated SrcSpanAnnA (Pat GhcRn)
-> WriterT
HsTyPatRnBuilder
(IOEnv (Env TcGblEnv TcLclEnv))
(GenLocated SrcSpanAnnA (HsType GhcRn))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. GenLocated SrcSpanAnnA (Pat GhcRn) -> Pat GhcRn
forall l e. GenLocated l e -> e
unLoc) [LPat GhcRn]
[GenLocated SrcSpanAnnA (Pat GhcRn)]
pats
; let t = HsType GhcRn -> GenLocated SrcSpanAnnA (HsType GhcRn)
forall e a. HasAnnotation e => a -> GenLocated e a
noLocA (XExplicitTupleTy GhcRn -> [LHsType GhcRn] -> HsType GhcRn
forall pass. XExplicitTupleTy pass -> [LHsType pass] -> HsType pass
HsExplicitTupleTy XExplicitTupleTy GhcRn
NoExtField
noExtField [LHsType GhcRn]
[GenLocated SrcSpanAnnA (HsType GhcRn)]
tys)
; pure t }
pat_to_type (ListPat XListPat GhcRn
_ [LPat GhcRn]
pats)
= do { tys <- (GenLocated SrcSpanAnnA (Pat GhcRn)
-> WriterT
HsTyPatRnBuilder
(IOEnv (Env TcGblEnv TcLclEnv))
(GenLocated SrcSpanAnnA (HsType GhcRn)))
-> [GenLocated SrcSpanAnnA (Pat GhcRn)]
-> WriterT
HsTyPatRnBuilder
(IOEnv (Env TcGblEnv TcLclEnv))
[GenLocated SrcSpanAnnA (HsType GhcRn)]
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> [a] -> f [b]
traverse (Pat GhcRn
-> WriterT
HsTyPatRnBuilder (IOEnv (Env TcGblEnv TcLclEnv)) (LHsType GhcRn)
Pat GhcRn
-> WriterT
HsTyPatRnBuilder
(IOEnv (Env TcGblEnv TcLclEnv))
(GenLocated SrcSpanAnnA (HsType GhcRn))
pat_to_type (Pat GhcRn
-> WriterT
HsTyPatRnBuilder
(IOEnv (Env TcGblEnv TcLclEnv))
(GenLocated SrcSpanAnnA (HsType GhcRn)))
-> (GenLocated SrcSpanAnnA (Pat GhcRn) -> Pat GhcRn)
-> GenLocated SrcSpanAnnA (Pat GhcRn)
-> WriterT
HsTyPatRnBuilder
(IOEnv (Env TcGblEnv TcLclEnv))
(GenLocated SrcSpanAnnA (HsType GhcRn))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. GenLocated SrcSpanAnnA (Pat GhcRn) -> Pat GhcRn
forall l e. GenLocated l e -> e
unLoc) [LPat GhcRn]
[GenLocated SrcSpanAnnA (Pat GhcRn)]
pats
; let t = HsType GhcRn -> GenLocated SrcSpanAnnA (HsType GhcRn)
forall e a. HasAnnotation e => a -> GenLocated e a
noLocA (XExplicitListTy GhcRn
-> PromotionFlag -> [LHsType GhcRn] -> HsType GhcRn
forall pass.
XExplicitListTy pass
-> PromotionFlag -> [LHsType pass] -> HsType pass
HsExplicitListTy XExplicitListTy GhcRn
NoExtField
NoExtField PromotionFlag
NotPromoted [LHsType GhcRn]
[GenLocated SrcSpanAnnA (HsType GhcRn)]
tys)
; pure t }
pat_to_type (LitPat XLitPat GhcRn
_ HsLit GhcRn
lit)
| Just HsTyLit GhcRn
ty_lit <- HsLit GhcRn -> Maybe (HsTyLit GhcRn)
tyLitFromLit HsLit GhcRn
lit
= do { let t :: GenLocated SrcSpanAnnA (HsType GhcRn)
t = HsType GhcRn -> GenLocated SrcSpanAnnA (HsType GhcRn)
forall e a. HasAnnotation e => a -> GenLocated e a
noLocA (XTyLit GhcRn -> HsTyLit GhcRn -> HsType GhcRn
forall pass. XTyLit pass -> HsTyLit pass -> HsType pass
HsTyLit XTyLit GhcRn
NoExtField
noExtField HsTyLit GhcRn
ty_lit)
; GenLocated SrcSpanAnnA (HsType GhcRn)
-> WriterT
HsTyPatRnBuilder
(IOEnv (Env TcGblEnv TcLclEnv))
(GenLocated SrcSpanAnnA (HsType GhcRn))
forall a.
a -> WriterT HsTyPatRnBuilder (IOEnv (Env TcGblEnv TcLclEnv)) a
forall (f :: * -> *) a. Applicative f => a -> f a
pure GenLocated SrcSpanAnnA (HsType GhcRn)
t }
pat_to_type (NPat XNPat GhcRn
_ (L EpAnnCO
_ HsOverLit GhcRn
lit) Maybe (SyntaxExpr GhcRn)
_ SyntaxExpr GhcRn
_)
| Just HsTyLit GhcRn
ty_lit <- OverLitVal -> Maybe (HsTyLit GhcRn)
tyLitFromOverloadedLit (HsOverLit GhcRn -> OverLitVal
forall p. HsOverLit p -> OverLitVal
ol_val HsOverLit GhcRn
lit)
= do { let t :: GenLocated SrcSpanAnnA (HsType GhcRn)
t = HsType GhcRn -> GenLocated SrcSpanAnnA (HsType GhcRn)
forall e a. HasAnnotation e => a -> GenLocated e a
noLocA (XTyLit GhcRn -> HsTyLit GhcRn -> HsType GhcRn
forall pass. XTyLit pass -> HsTyLit pass -> HsType pass
HsTyLit XTyLit GhcRn
NoExtField
noExtField HsTyLit GhcRn
ty_lit)
; GenLocated SrcSpanAnnA (HsType GhcRn)
-> WriterT
HsTyPatRnBuilder
(IOEnv (Env TcGblEnv TcLclEnv))
(GenLocated SrcSpanAnnA (HsType GhcRn))
forall a.
a -> WriterT HsTyPatRnBuilder (IOEnv (Env TcGblEnv TcLclEnv)) a
forall (f :: * -> *) a. Applicative f => a -> f a
pure GenLocated SrcSpanAnnA (HsType GhcRn)
t}
pat_to_type (ConPat XConPat GhcRn
_ XRec GhcRn (ConLikeP GhcRn)
lname (InfixCon LPat GhcRn
left LPat GhcRn
right))
= do { lty <- Pat GhcRn
-> WriterT
HsTyPatRnBuilder (IOEnv (Env TcGblEnv TcLclEnv)) (LHsType GhcRn)
pat_to_type (GenLocated SrcSpanAnnA (Pat GhcRn) -> Pat GhcRn
forall l e. GenLocated l e -> e
unLoc LPat GhcRn
GenLocated SrcSpanAnnA (Pat GhcRn)
left)
; rty <- pat_to_type (unLoc right)
; let { t = HsType GhcRn -> GenLocated SrcSpanAnnA (HsType GhcRn)
forall e a. HasAnnotation e => a -> GenLocated e a
noLocA (XOpTy GhcRn
-> PromotionFlag
-> LHsType GhcRn
-> LIdP GhcRn
-> LHsType GhcRn
-> HsType GhcRn
forall pass.
XOpTy pass
-> PromotionFlag
-> LHsType pass
-> LIdP pass
-> LHsType pass
-> HsType pass
HsOpTy XOpTy GhcRn
NoExtField
noExtField PromotionFlag
NotPromoted LHsType GhcRn
GenLocated SrcSpanAnnA (HsType GhcRn)
lty LIdP GhcRn
XRec GhcRn (ConLikeP GhcRn)
lname LHsType GhcRn
GenLocated SrcSpanAnnA (HsType GhcRn)
rty)}
; pure t }
pat_to_type (ConPat XConPat GhcRn
_ XRec GhcRn (ConLikeP GhcRn)
lname (PrefixCon [HsConPatTyArg (NoGhcTc GhcRn)]
invis_args [LPat GhcRn]
vis_args))
= do { let { appHead :: GenLocated SrcSpanAnnA (HsType GhcRn)
appHead = HsType GhcRn -> GenLocated SrcSpanAnnA (HsType GhcRn)
forall e a. HasAnnotation e => a -> GenLocated e a
noLocA (XTyVar GhcRn -> PromotionFlag -> LIdP GhcRn -> HsType GhcRn
forall pass.
XTyVar pass -> PromotionFlag -> LIdP pass -> HsType pass
HsTyVar XTyVar GhcRn
forall a. NoAnn a => a
noAnn PromotionFlag
NotPromoted LIdP GhcRn
XRec GhcRn (ConLikeP GhcRn)
lname)}
; ty_invis <- (GenLocated SrcSpanAnnA (HsType GhcRn)
-> HsConPatTyArg GhcRn
-> WriterT
HsTyPatRnBuilder
(IOEnv (Env TcGblEnv TcLclEnv))
(GenLocated SrcSpanAnnA (HsType GhcRn)))
-> GenLocated SrcSpanAnnA (HsType GhcRn)
-> [HsConPatTyArg GhcRn]
-> WriterT
HsTyPatRnBuilder
(IOEnv (Env TcGblEnv TcLclEnv))
(GenLocated SrcSpanAnnA (HsType GhcRn))
forall (t :: * -> *) (m :: * -> *) b a.
(Foldable t, Monad m) =>
(b -> a -> m b) -> b -> t a -> m b
foldM LHsType GhcRn
-> HsConPatTyArg GhcRn
-> WriterT
HsTyPatRnBuilder (IOEnv (Env TcGblEnv TcLclEnv)) (LHsType GhcRn)
GenLocated SrcSpanAnnA (HsType GhcRn)
-> HsConPatTyArg GhcRn
-> WriterT
HsTyPatRnBuilder
(IOEnv (Env TcGblEnv TcLclEnv))
(GenLocated SrcSpanAnnA (HsType GhcRn))
apply_invis_arg GenLocated SrcSpanAnnA (HsType GhcRn)
appHead [HsConPatTyArg (NoGhcTc GhcRn)]
[HsConPatTyArg GhcRn]
invis_args
; tys_vis <- traverse (pat_to_type . unLoc) vis_args
; let t = (GenLocated SrcSpanAnnA (HsType GhcRn)
-> GenLocated SrcSpanAnnA (HsType GhcRn)
-> GenLocated SrcSpanAnnA (HsType GhcRn))
-> GenLocated SrcSpanAnnA (HsType GhcRn)
-> [GenLocated SrcSpanAnnA (HsType GhcRn)]
-> GenLocated SrcSpanAnnA (HsType GhcRn)
forall b a. (b -> a -> b) -> b -> [a] -> b
forall (t :: * -> *) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
foldl' LHsType GhcRn -> LHsType GhcRn -> LHsType GhcRn
GenLocated SrcSpanAnnA (HsType GhcRn)
-> GenLocated SrcSpanAnnA (HsType GhcRn)
-> GenLocated SrcSpanAnnA (HsType GhcRn)
forall (p :: Pass).
LHsType (GhcPass p) -> LHsType (GhcPass p) -> LHsType (GhcPass p)
mkHsAppTy GenLocated SrcSpanAnnA (HsType GhcRn)
ty_invis [GenLocated SrcSpanAnnA (HsType GhcRn)]
tys_vis
; pure t }
where
apply_invis_arg :: LHsType GhcRn -> HsConPatTyArg GhcRn -> WriterT HsTyPatRnBuilder TcM (LHsType GhcRn)
apply_invis_arg :: LHsType GhcRn
-> HsConPatTyArg GhcRn
-> WriterT
HsTyPatRnBuilder (IOEnv (Env TcGblEnv TcLclEnv)) (LHsType GhcRn)
apply_invis_arg !LHsType GhcRn
t (HsConPatTyArg XConPatTyArg GhcRn
_ (HsTP XHsTP GhcRn
argx LHsType GhcRn
arg))
= do { HsTyPatRnBuilder
-> WriterT HsTyPatRnBuilder (IOEnv (Env TcGblEnv TcLclEnv)) ()
forall w (m :: * -> *). (Monoid w, Monad m) => w -> WriterT w m ()
tell (HsTyPatRn -> HsTyPatRnBuilder
builderFromHsTyPatRn XHsTP GhcRn
HsTyPatRn
argx)
; GenLocated SrcSpanAnnA (HsType GhcRn)
-> WriterT
HsTyPatRnBuilder
(IOEnv (Env TcGblEnv TcLclEnv))
(GenLocated SrcSpanAnnA (HsType GhcRn))
forall a.
a -> WriterT HsTyPatRnBuilder (IOEnv (Env TcGblEnv TcLclEnv)) a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (XAppKindTy GhcRn -> LHsType GhcRn -> LHsType GhcRn -> LHsType GhcRn
forall (p :: Pass).
XAppKindTy (GhcPass p)
-> LHsType (GhcPass p)
-> LHsType (GhcPass p)
-> LHsType (GhcPass p)
mkHsAppKindTy XAppKindTy GhcRn
NoExtField
noExtField LHsType GhcRn
t LHsType GhcRn
arg)}
pat_to_type Pat GhcRn
pat = TcM (LHsType GhcRn)
-> WriterT
HsTyPatRnBuilder (IOEnv (Env TcGblEnv TcLclEnv)) (LHsType GhcRn)
forall (m :: * -> *) a.
Monad m =>
m a -> WriterT HsTyPatRnBuilder m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (TcM (LHsType GhcRn)
-> WriterT
HsTyPatRnBuilder (IOEnv (Env TcGblEnv TcLclEnv)) (LHsType GhcRn))
-> TcM (LHsType GhcRn)
-> WriterT
HsTyPatRnBuilder (IOEnv (Env TcGblEnv TcLclEnv)) (LHsType GhcRn)
forall a b. (a -> b) -> a -> b
$
TcRnMessage -> TcM (LHsType GhcRn)
forall a. TcRnMessage -> TcRn a
failWith (TcRnMessage -> TcM (LHsType GhcRn))
-> TcRnMessage -> TcM (LHsType GhcRn)
forall a b. (a -> b) -> a -> b
$ Pat GhcRn -> TcRnMessage
TcRnIllformedTypePattern Pat GhcRn
pat
tc_ty_pat :: HsTyPat GhcRn -> TcTyVar -> TcM r -> TcM (TcType, r)
tc_ty_pat :: forall r. HsTyPat GhcRn -> TyCoVar -> TcM r -> TcM (Type, r)
tc_ty_pat HsTyPat GhcRn
tp TyCoVar
tv TcM r
thing_inside
= do { (sig_wcs, sig_ibs, arg_ty) <- HsTyPat GhcRn
-> Type -> TcM ([(Name, TyCoVar)], [(Name, TyCoVar)], Type)
tcHsTyPat HsTyPat GhcRn
tp (TyCoVar -> Type
varType TyCoVar
tv)
; _ <- unifyType Nothing arg_ty (mkTyVarTy tv)
; result <- tcExtendNameTyVarEnv sig_wcs $
tcExtendNameTyVarEnv sig_ibs $
thing_inside
; return (arg_ty, result) }
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
{ (wrap, id) <- PatEnv
-> Name -> Scaled ExpSigmaTypeFRR -> TcM (HsWrapper, TyCoVar)
tcPatBndr PatEnv
penv Name
name Scaled ExpSigmaTypeFRR
pat_ty
; res <- tcCheckUsage name (scaledMult pat_ty) $
tcExtendIdEnv1 name id thing_inside
; pat_ty <- readExpType (scaledThing pat_ty)
; return (mkHsWrapPat wrap (VarPat x (L l id)) pat_ty, res) }
ParPat XParPat GhcRn
x LPat GhcRn
pat -> do
{ (pat', res) <- Scaled ExpSigmaTypeFRR -> Checker (LPat GhcRn) (LPat GhcTc)
tc_lpat Scaled ExpSigmaTypeFRR
pat_ty PatEnv
penv LPat GhcRn
pat TcM r
thing_inside
; return (ParPat x pat', res) }
BangPat XBangPat GhcRn
x LPat GhcRn
pat -> do
{ (pat', res) <- Scaled ExpSigmaTypeFRR -> Checker (LPat GhcRn) (LPat GhcTc)
tc_lpat Scaled ExpSigmaTypeFRR
pat_ty PatEnv
penv LPat GhcRn
pat TcM r
thing_inside
; return (BangPat x pat', res) }
OrPat XOrPat GhcRn
_ NonEmpty (LPat GhcRn)
pats -> do
{ let pats_list :: [GenLocated SrcSpanAnnA (Pat GhcRn)]
pats_list = NonEmpty (GenLocated SrcSpanAnnA (Pat GhcRn))
-> [GenLocated SrcSpanAnnA (Pat GhcRn)]
forall a. NonEmpty a -> [a]
NE.toList NonEmpty (LPat GhcRn)
NonEmpty (GenLocated SrcSpanAnnA (Pat GhcRn))
pats
; (pats_list', (res, pat_ct)) <- [Scaled ExpSigmaTypeFRR] -> Checker [LPat GhcRn] [LPat GhcTc]
tc_lpats ((GenLocated SrcSpanAnnA (Pat GhcRn) -> Scaled ExpSigmaTypeFRR)
-> [GenLocated SrcSpanAnnA (Pat GhcRn)] -> [Scaled ExpSigmaTypeFRR]
forall a b. (a -> b) -> [a] -> [b]
map (Scaled ExpSigmaTypeFRR
-> GenLocated SrcSpanAnnA (Pat GhcRn) -> Scaled ExpSigmaTypeFRR
forall a b. a -> b -> a
const Scaled ExpSigmaTypeFRR
pat_ty) [GenLocated SrcSpanAnnA (Pat GhcRn)]
pats_list) PatEnv
penv [LPat GhcRn]
[GenLocated SrcSpanAnnA (Pat GhcRn)]
pats_list (TcM r -> TcM (r, WantedConstraints)
forall a. TcM a -> TcM (a, WantedConstraints)
captureConstraints TcM r
thing_inside)
; let pats' = [GenLocated SrcSpanAnnA (Pat GhcTc)]
-> NonEmpty (GenLocated SrcSpanAnnA (Pat GhcTc))
forall a. HasCallStack => [a] -> NonEmpty a
NE.fromList [GenLocated SrcSpanAnnA (Pat GhcTc)]
pats_list'
; emitConstraints pat_ct
; pat_ty <- expTypeToType (scaledThing pat_ty)
; return (OrPat pat_ty pats', res) }
LazyPat XLazyPat GhcRn
x LPat GhcRn
pat -> do
{ NonLinearPatternReason
-> LPat GhcRn -> Scaled ExpSigmaTypeFRR -> TcM ()
forall a.
NonLinearPatternReason -> LPat GhcRn -> Scaled a -> TcM ()
checkManyPattern NonLinearPatternReason
LazyPatternReason (Pat GhcRn -> GenLocated SrcSpanAnnA (Pat GhcRn)
forall e a. HasAnnotation e => a -> GenLocated e a
noLocA Pat GhcRn
ps_pat) Scaled ExpSigmaTypeFRR
pat_ty
; (pat', (res, 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
; emitConstraints pat_ct
; pat_ty <- readExpType (scaledThing pat_ty)
; _ <- unifyType Nothing (typeKind pat_ty) liftedTypeKind
; return ((LazyPat x pat'), res) }
WildPat XWildPat GhcRn
_ -> do
{ NonLinearPatternReason
-> LPat GhcRn -> Scaled ExpSigmaTypeFRR -> TcM ()
forall a.
NonLinearPatternReason -> LPat GhcRn -> Scaled a -> TcM ()
checkManyPattern NonLinearPatternReason
OtherPatternReason (Pat GhcRn -> GenLocated SrcSpanAnnA (Pat GhcRn)
forall e a. HasAnnotation e => a -> GenLocated e a
noLocA Pat GhcRn
ps_pat) Scaled ExpSigmaTypeFRR
pat_ty
; res <- TcM r
thing_inside
; pat_ty <- expTypeToType (scaledThing pat_ty)
; return (WildPat pat_ty, res) }
AsPat XAsPat GhcRn
x (L SrcSpanAnnN
nm_loc Name
name) LPat GhcRn
pat -> do
{ NonLinearPatternReason
-> LPat GhcRn -> Scaled ExpSigmaTypeFRR -> TcM ()
forall a.
NonLinearPatternReason -> LPat GhcRn -> Scaled a -> TcM ()
checkManyPattern NonLinearPatternReason
OtherPatternReason (Pat GhcRn -> GenLocated SrcSpanAnnA (Pat GhcRn)
forall e a. HasAnnotation e => a -> GenLocated e a
noLocA Pat GhcRn
ps_pat) Scaled ExpSigmaTypeFRR
pat_ty
; (wrap, bndr_id) <- SrcSpanAnnN -> TcM (HsWrapper, TyCoVar) -> TcM (HsWrapper, TyCoVar)
forall ann a. EpAnn 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)
; (pat', res) <- tcExtendIdEnv1 name bndr_id $
tc_lpat (pat_ty `scaledSet`(mkCheckExpType $ idType bndr_id))
penv pat thing_inside
; pat_ty <- readExpType (scaledThing pat_ty)
; return (mkHsWrapPat wrap (AsPat x (L nm_loc bndr_id) pat') pat_ty, res) }
ViewPat XViewPat GhcRn
_ LHsExpr GhcRn
expr LPat GhcRn
pat -> do
{ NonLinearPatternReason
-> LPat GhcRn -> Scaled ExpSigmaTypeFRR -> TcM ()
forall a.
NonLinearPatternReason -> LPat GhcRn -> Scaled a -> TcM ()
checkManyPattern NonLinearPatternReason
ViewPatternReason (Pat GhcRn -> GenLocated SrcSpanAnnA (Pat GhcRn)
forall e a. HasAnnotation e => a -> GenLocated e a
noLocA Pat GhcRn
ps_pat) Scaled ExpSigmaTypeFRR
pat_ty
; (expr',expr_ty) <- LHsExpr GhcRn -> TcM (LHsExpr GhcTc, Type)
tcInferRho LHsExpr GhcRn
expr
; let 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
; (expr_wrap1, Scaled _mult inf_arg_ty, inf_res_sigma)
<- matchActualFunTy herald (Just . HsExprRnThing $ unLoc expr) (1,expr_ty) expr_ty
; expr_wrap2 <- tc_sub_type penv (scaledThing pat_ty) inf_arg_ty
; (pat', res) <- tc_lpat (pat_ty `scaledSet` mkCheckExpType inf_res_sigma) penv pat thing_inside
; let Scaled w h_pat_ty = pat_ty
; pat_ty <- readExpType h_pat_ty
; let 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_wrap2' HsWrapper -> HsWrapper -> HsWrapper
<.> HsWrapper
expr_wrap1
; return $ (ViewPat pat_ty (mkLHsWrap expr_wrap expr') pat', res) }
SigPat XSigPat GhcRn
_ LPat GhcRn
pat HsPatSigType (NoGhcTc GhcRn)
sig_ty -> do
{ (inner_ty, tv_binds, wcs, 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)
; (pat', res) <- tcExtendNameTyVarEnv wcs $
tcExtendNameTyVarEnv tv_binds $
tc_lpat (pat_ty `scaledSet` mkCheckExpType inner_ty) penv pat thing_inside
; pat_ty <- readExpType (scaledThing pat_ty)
; return (mkHsWrapPat wrap (SigPat inner_ty pat' sig_ty) pat_ty, res) }
ListPat XListPat GhcRn
_ [LPat GhcRn]
pats -> do
{ (coi, 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)
; (pats', res) <- tcMultiple (tc_lpat (pat_ty `scaledSet` mkCheckExpType elt_ty))
penv pats thing_inside
; pat_ty <- readExpType (scaledThing pat_ty)
; return (mkHsWrapPat coi
(ListPat elt_ty pats') pat_ty, 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 -> TcM ()
checkTupSize Int
arity
; (coi, 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 = 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
; (pats', res) <- tc_lpats (map (scaledSet pat_ty . mkCheckExpType) con_arg_tys)
penv pats thing_inside
; dflags <- getDynFlags
; let
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
| 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 e a. HasAnnotation e => a -> GenLocated e a
noLocA Pat GhcTc
unmangled_result)
| Bool
otherwise = Pat GhcTc
unmangled_result
; pat_ty <- readExpType (scaledThing pat_ty)
; massert (con_arg_tys `equalLength` pats)
; return (mkHsWrapPat coi possibly_mangled_result pat_ty, res)
}
SumPat XSumPat GhcRn
_ LPat GhcRn
pat Int
alt Int
arity -> do
{ let tc :: TyCon
tc = Int -> TyCon
sumTyCon Int
arity
; (coi, 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 = Int -> [Type] -> [Type]
forall a. Int -> [a] -> [a]
drop Int
arity [Type]
arg_tys
; (pat', res) <- tc_lpat (pat_ty `scaledSet` mkCheckExpType (con_arg_tys `getNth` (alt - 1)))
penv pat thing_inside
; pat_ty <- readExpType (scaledThing pat_ty)
; return (mkHsWrapPat coi (SumPat con_arg_tys pat' alt arity) pat_ty
, res)
}
ConPat XConPat GhcRn
_ XRec GhcRn (ConLikeP GhcRn)
con HsConDetails
(HsConPatTyArg (NoGhcTc GhcRn))
(LPat GhcRn)
(HsRecFields GhcRn (LPat GhcRn))
arg_pats ->
PatEnv
-> GenLocated SrcSpanAnnN Name
-> Scaled ExpSigmaTypeFRR
-> HsConDetails
(HsConPatTyArg (NoGhcTc GhcRn))
(LPat GhcRn)
(HsRecFields GhcRn (LPat GhcRn))
-> TcM r
-> TcM (Pat GhcTc, r)
forall a.
PatEnv
-> GenLocated SrcSpanAnnN Name
-> Scaled ExpSigmaTypeFRR
-> HsConDetails
(HsConPatTyArg (NoGhcTc GhcRn))
(LPat GhcRn)
(HsRecFields GhcRn (LPat GhcRn))
-> TcM a
-> TcM (Pat GhcTc, a)
tcConPat PatEnv
penv XRec GhcRn (ConLikeP GhcRn)
GenLocated SrcSpanAnnN Name
con Scaled ExpSigmaTypeFRR
pat_ty HsConDetails
(HsConPatTyArg (NoGhcTc GhcRn))
(LPat GhcRn)
(HsRecFields GhcRn (LPat 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). IsPass p => HsLit (GhcPass p) -> Type
hsLitType HsLit GhcRn
simple_lit
; 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
; res <- thing_inside
; pat_ty <- readExpType (scaledThing pat_ty)
; return ( mkHsWrapPat wrap (LitPat x (convertLit simple_lit)) pat_ty
, res) }
NPat XNPat GhcRn
_ (L EpAnnCO
l HsOverLit GhcRn
over_lit) Maybe (SyntaxExpr GhcRn)
mb_neg SyntaxExpr GhcRn
eq -> do
{ NonLinearPatternReason
-> LPat GhcRn -> Scaled ExpSigmaTypeFRR -> TcM ()
forall a.
NonLinearPatternReason -> LPat GhcRn -> Scaled a -> TcM ()
checkManyPattern NonLinearPatternReason
OtherPatternReason (Pat GhcRn -> GenLocated SrcSpanAnnA (Pat GhcRn)
forall e a. HasAnnotation e => a -> GenLocated e a
noLocA Pat GhcRn
ps_pat) Scaled ExpSigmaTypeFRR
pat_ty
; let orig :: CtOrigin
orig = HsOverLit GhcRn -> CtOrigin
LiteralOrigin HsOverLit GhcRn
over_lit
; ((lit', mb_neg'), 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)
; res <- thing_inside
; pat_ty <- readExpType (scaledThing pat_ty)
; return (NPat pat_ty (L l lit') mb_neg' eq', res) }
NPlusKPat XNPlusKPat GhcRn
_ (L SrcSpanAnnN
nm_loc Name
name)
(L EpAnnCO
loc HsOverLit GhcRn
lit) HsOverLit GhcRn
_ SyntaxExpr GhcRn
ge SyntaxExpr GhcRn
minus -> do
{ NonLinearPatternReason
-> LPat GhcRn -> Scaled ExpSigmaTypeFRR -> TcM ()
forall a.
NonLinearPatternReason -> LPat GhcRn -> Scaled a -> TcM ()
checkManyPattern NonLinearPatternReason
OtherPatternReason (Pat GhcRn -> GenLocated SrcSpanAnnA (Pat GhcRn)
forall e a. HasAnnotation e => a -> GenLocated e a
noLocA Pat GhcRn
ps_pat) 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
; (lit1', 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)
; ((lit2', minus_wrap, bndr_id), minus')
<- tcSyntaxOpGen orig minus [SynType pat_exp_ty, SynRho] SynAny $
\ [Type
lit2_ty, Type
var_ty] [Type]
_ ->
do { lit2' <- HsOverLit GhcRn -> ExpSigmaTypeFRR -> TcM (HsOverLit GhcTc)
newOverloadedLit HsOverLit GhcRn
lit (Type -> ExpSigmaTypeFRR
mkCheckExpType Type
lit2_ty)
; (wrap, bndr_id) <- setSrcSpanA nm_loc $
tcPatBndr penv name (unrestricted $ mkCheckExpType var_ty)
; return (lit2', wrap, bndr_id) }
; pat_ty <- readExpType pat_exp_ty
; unlessM (xoptM LangExt.RebindableSyntax) $
do { icls <- tcLookupClass integralClassName
; instStupidTheta orig [mkClassPred icls [pat_ty]] }
; res <- tcExtendIdEnv1 name bndr_id thing_inside
; let 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' = 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) (EpAnnCO -> HsOverLit GhcTc -> GenLocated EpAnnCO (HsOverLit GhcTc)
forall l e. l -> e -> GenLocated l e
L EpAnnCO
loc HsOverLit GhcTc
lit1') HsOverLit GhcTc
lit2'
SyntaxExpr GhcTc
SyntaxExprTc
ge' SyntaxExpr GhcTc
SyntaxExprTc
minus''
; return (pat', res) }
SplicePat (HsUntypedSpliceTop ThModFinalizers
mod_finalizers Pat GhcRn
pat) HsUntypedSplice GhcRn
_ -> do
{ ThModFinalizers -> TcM ()
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"
EmbTyPat XEmbTyPat GhcRn
_ HsTyPat (NoGhcTc GhcRn)
_ -> TcRnMessage -> TcM (Pat GhcTc, r)
forall a. TcRnMessage -> TcRn a
failWith TcRnMessage
TcRnIllegalTypePattern
InvisPat XInvisPat GhcRn
_ HsTyPat (NoGhcTc GhcRn)
_ -> String -> TcM (Pat GhcTc, r)
forall a. HasCallStack => String -> a
panic String
"tc_pat: invisible pattern appears recursively in the pattern"
XPat (HsPatExpanded Pat GhcRn
lpat Pat GhcRn
rpat) -> do
{ (rpat', res) <- Scaled ExpSigmaTypeFRR -> Checker (Pat GhcRn) (Pat GhcTc)
tc_pat Scaled ExpSigmaTypeFRR
pat_ty PatEnv
penv Pat GhcRn
rpat TcM r
thing_inside
; return (XPat $ ExpansionPat lpat rpat', 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 { (sig_wcs, sig_tvs, 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 NE.nonEmpty sig_tvs of
Maybe (NonEmpty (Name, TyCoVar))
Nothing -> do {
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
; return (sig_ty, [], sig_wcs, wrap)
}
Just NonEmpty (Name, TyCoVar)
sig_tvs_ne -> do
Bool -> TcM () -> TcM ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when Bool
in_pat_bind
(TcRnMessage -> TcM ()
addErr (NonEmpty (Name, TyCoVar) -> TcRnMessage
TcRnCannotBindScopedTyVarInPatSig NonEmpty (Name, TyCoVar)
sig_tvs_ne))
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
return (sig_ty, sig_tvs, sig_wcs, wrap)
}
where
mk_msg :: Type -> TidyEnv -> ZonkM (TidyEnv, SDoc)
mk_msg Type
sig_ty TidyEnv
tidy_env
= do { (tidy_env, sig_ty) <- TidyEnv -> Type -> ZonkM (TidyEnv, Type)
zonkTidyTcType TidyEnv
tidy_env Type
sig_ty
; res_ty <- readExpType res_ty
; (tidy_env, res_ty) <- zonkTidyTcType tidy_env res_ty
; let 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)) ]
; return (tidy_env, msg) }
tcConPat :: PatEnv -> LocatedN Name
-> Scaled ExpSigmaTypeFRR
-> HsConPatDetails GhcRn -> TcM a
-> TcM (Pat GhcTc, a)
tcConPat :: forall a.
PatEnv
-> GenLocated SrcSpanAnnN Name
-> Scaled ExpSigmaTypeFRR
-> HsConDetails
(HsConPatTyArg (NoGhcTc GhcRn))
(LPat GhcRn)
(HsRecFields GhcRn (LPat 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 HsConDetails
(HsConPatTyArg (NoGhcTc GhcRn))
(LPat GhcRn)
(HsRecFields GhcRn (LPat GhcRn))
arg_pats TcM a
thing_inside
= do { con_like <- Name -> TcM ConLike
tcLookupConLike Name
con_name
; case con_like of
RealDataCon DataCon
data_con -> GenLocated SrcSpanAnnN Name
-> DataCon
-> Scaled ExpSigmaTypeFRR
-> Checker
(HsConDetails
(HsConPatTyArg (NoGhcTc GhcRn))
(LPat GhcRn)
(HsRecFields GhcRn (LPat GhcRn)))
(Pat GhcTc)
tcDataConPat GenLocated SrcSpanAnnN Name
con_lname DataCon
data_con Scaled ExpSigmaTypeFRR
pat_ty
PatEnv
penv HsConDetails
(HsConPatTyArg (NoGhcTc GhcRn))
(LPat GhcRn)
(HsRecFields GhcRn (LPat GhcRn))
arg_pats TcM a
thing_inside
PatSynCon PatSyn
pat_syn -> GenLocated SrcSpanAnnN Name
-> PatSyn
-> Scaled ExpSigmaTypeFRR
-> Checker
(HsConDetails
(HsConPatTyArg (NoGhcTc GhcRn))
(LPat GhcRn)
(HsRecFields GhcRn (LPat GhcRn)))
(Pat GhcTc)
tcPatSynPat GenLocated SrcSpanAnnN Name
con_lname PatSyn
pat_syn Scaled ExpSigmaTypeFRR
pat_ty
PatEnv
penv HsConDetails
(HsConPatTyArg (NoGhcTc GhcRn))
(LPat GhcRn)
(HsRecFields GhcRn (LPat GhcRn))
arg_pats TcM a
thing_inside
}
warnMonoLocalBinds :: TcM ()
warnMonoLocalBinds :: TcM ()
warnMonoLocalBinds
= do { mono_local_binds <- Extension -> IOEnv (Env TcGblEnv TcLclEnv) Bool
forall gbl lcl. Extension -> TcRnIf gbl lcl Bool
xoptM Extension
LangExt.MonoLocalBinds
; unless mono_local_binds $
addDiagnostic TcRnGADTMonoLocalBinds
}
tcDataConPat :: LocatedN Name -> DataCon
-> Scaled ExpSigmaTypeFRR
-> Checker (HsConPatDetails GhcRn) (Pat GhcTc)
tcDataConPat :: GenLocated SrcSpanAnnN Name
-> DataCon
-> Scaled ExpSigmaTypeFRR
-> Checker
(HsConDetails
(HsConPatTyArg (NoGhcTc GhcRn))
(LPat GhcRn)
(HsRecFields GhcRn (LPat GhcRn)))
(Pat GhcTc)
tcDataConPat (L SrcSpanAnnN
con_span Name
con_name) DataCon
data_con Scaled ExpSigmaTypeFRR
pat_ty_scaled
PatEnv
penv HsConDetails
(HsConPatTyArg (NoGhcTc GhcRn))
(LPat GhcRn)
(HsRecFields GhcRn (LPat 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)
; (wrap, ctxt_res_tys) <- PatEnv
-> TyCon -> Scaled ExpSigmaTypeFRR -> TcM (HsWrapper, [Type])
matchExpectedConTy PatEnv
penv TyCon
tycon Scaled ExpSigmaTypeFRR
pat_ty_scaled
; pat_ty <- readExpType (scaledThing pat_ty_scaled)
; setSrcSpanA con_span $ addDataConStupidTheta data_con ctxt_res_tys
; let 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)
; checkGADT (RealDataCon data_con) ex_tvs all_arg_tys penv
; tenv1 <- instTyVarsWith PatOrigin univ_tvs ctxt_res_tys
; let mc = case PatEnv -> PatCtxt
pe_ctxt PatEnv
penv of
LamPat HsMatchContextRn
mc -> HsMatchContextRn
mc
LetPat {} -> HsMatchContextRn
HsMatchContext (GenLocated SrcSpanAnnN Name)
forall fn. HsMatchContext fn
PatBindRhs
; skol_info <- mkSkolemInfo (PatSkol (RealDataCon data_con) mc)
; (tenv, ex_tvs') <- tcInstSuperSkolTyVarsX skol_info tenv1 ex_tvs
; let arg_tys' = HasDebugCallStack => Subst -> [Scaled Type] -> [Scaled Type]
Subst -> [Scaled Type] -> [Scaled Type]
substScaledTys Subst
tenv [Scaled Type]
arg_tys
pat_mult = Scaled ExpSigmaTypeFRR -> Type
forall a. Scaled a -> Type
scaledMult Scaled ExpSigmaTypeFRR
pat_ty_scaled
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 = DataCon -> ConLike
RealDataCon DataCon
data_con
; checkFixedRuntimeRep data_con arg_tys'
; traceTc "tcConPat" (vcat [ text "con_name:" <+> ppr con_name
, text "univ_tvs:" <+> pprTyVars univ_tvs
, text "ex_tvs:" <+> pprTyVars ex_tvs
, text "eq_spec:" <+> ppr eq_spec
, text "theta:" <+> ppr theta
, text "ex_tvs':" <+> pprTyVars ex_tvs'
, text "ctxt_res_tys:" <+> ppr ctxt_res_tys
, text "pat_ty:" <+> ppr pat_ty
, text "arg_tys':" <+> ppr arg_tys'
, text "arg_pats" <+> ppr arg_pats ])
; (univ_ty_args, ex_ty_args) <- splitConTyArgs con_like arg_pats
; if null ex_tvs && null eq_spec && null theta
then do {
(arg_pats', res) <- tcConTyArgs tenv penv univ_ty_args $
tcConValArgs con_like arg_tys_scaled
penv arg_pats thing_inside
; let 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
}
}
; return (mkHsWrapPat wrap res_pat pat_ty, res) }
else do
{ let 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)
; when (not (null eq_spec) || any isEqClassPred theta) warnMonoLocalBinds
; given <- newEvVars theta'
; (ev_binds, (arg_pats', res))
<-
tcConTyArgs tenv penv univ_ty_args $
checkConstraints (getSkolemInfo skol_info) ex_tvs' given $
tcConTyArgs tenv penv ex_ty_args $
tcConValArgs con_like arg_tys_scaled penv arg_pats thing_inside
; let 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
}
}
; return (mkHsWrapPat wrap res_pat pat_ty, res)
} }
tcPatSynPat :: LocatedN Name -> PatSyn
-> Scaled ExpSigmaType
-> Checker (HsConPatDetails GhcRn) (Pat GhcTc)
tcPatSynPat :: GenLocated SrcSpanAnnN Name
-> PatSyn
-> Scaled ExpSigmaTypeFRR
-> Checker
(HsConDetails
(HsConPatTyArg (NoGhcTc GhcRn))
(LPat GhcRn)
(HsRecFields GhcRn (LPat GhcRn)))
(Pat GhcTc)
tcPatSynPat (L SrcSpanAnnN
con_span Name
con_name) PatSyn
pat_syn Scaled ExpSigmaTypeFRR
pat_ty PatEnv
penv HsConDetails
(HsConPatTyArg (NoGhcTc GhcRn))
(LPat GhcRn)
(HsRecFields GhcRn (LPat 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, univ_tvs') <- [TyCoVar] -> TcM (Subst, [TyCoVar])
newMetaTyVars [TyCoVar]
univ_tvs
; let 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)
; checkGADT (PatSynCon pat_syn) ex_tvs all_arg_tys penv
; skol_info <- case pe_ctxt penv of
LamPat HsMatchContextRn
mc -> SkolemInfoAnon -> IOEnv (Env TcGblEnv TcLclEnv) SkolemInfo
forall (m :: * -> *). MonadIO m => SkolemInfoAnon -> m SkolemInfo
mkSkolemInfo (ConLike -> HsMatchContextRn -> SkolemInfoAnon
PatSkol (PatSyn -> ConLike
PatSynCon PatSyn
pat_syn) HsMatchContextRn
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
; (tenv, ex_tvs') <- tcInstSuperSkolTyVarsX skol_info subst ex_tvs
; let ty' = HasDebugCallStack => Subst -> Type -> Type
Subst -> Type -> Type
substTy Subst
tenv Type
ty
arg_tys' = HasDebugCallStack => Subst -> [Scaled Type] -> [Scaled Type]
Subst -> [Scaled Type] -> [Scaled Type]
substScaledTys Subst
tenv [Scaled Type]
arg_tys
pat_mult = Scaled ExpSigmaTypeFRR -> Type
forall a. Scaled a -> Type
scaledMult Scaled ExpSigmaTypeFRR
pat_ty
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' = HasDebugCallStack => Subst -> [Type] -> [Type]
Subst -> [Type] -> [Type]
substTheta Subst
tenv [Type]
prov_theta
req_theta' = HasDebugCallStack => Subst -> [Type] -> [Type]
Subst -> [Type] -> [Type]
substTheta Subst
tenv [Type]
req_theta
con_like = PatSyn -> ConLike
PatSynCon PatSyn
pat_syn
; when (any isEqClassPred prov_theta) warnMonoLocalBinds
; checkManyPattern PatternSynonymReason nlWildPatName pat_ty
; (univ_ty_args, ex_ty_args) <- splitConTyArgs con_like arg_pats
; wrap <- tc_sub_type penv (scaledThing pat_ty) ty'
; traceTc "tcPatSynPat" $
vcat [ text "Pat syn:" <+> ppr pat_syn
, text "Expected type:" <+> ppr pat_ty
, text "Pat res ty:" <+> ppr ty'
, text "ex_tvs':" <+> pprTyVars ex_tvs'
, text "prov_theta':" <+> ppr prov_theta'
, text "req_theta':" <+> ppr req_theta'
, text "arg_tys':" <+> ppr arg_tys'
, text "univ_ty_args:" <+> ppr univ_ty_args
, text "ex_ty_args:" <+> ppr ex_ty_args ]
; req_wrap <- instCall (OccurrenceOf con_name) (mkTyVarTys univ_tvs') req_theta'
; traceTc "instCall" (ppr req_wrap)
; let
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) -> Bool -> Bool
not (HasDebugCallStack => Type -> Bool
Type -> Bool
typeHasFixedRuntimeRep Type
arg_ty))
([(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'
; massertPpr (null bad_arg_tys) $
vcat [ text "tcPatSynPat: pattern arguments do not have a fixed RuntimeRep"
, text "bad_arg_tys:" <+> ppr bad_arg_tys ]
; traceTc "checkConstraints {" Outputable.empty
; prov_dicts' <- newEvVars prov_theta'
; (ev_binds, (arg_pats', res))
<-
tcConTyArgs tenv penv univ_ty_args $
checkConstraints (getSkolemInfo skol_info) ex_tvs' prov_dicts' $
tcConTyArgs tenv penv ex_ty_args $
tcConValArgs con_like arg_tys_scaled penv arg_pats $
thing_inside
; traceTc "checkConstraints }" (ppr ev_binds)
; let 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
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
}
}
; pat_ty <- readExpType (scaledThing pat_ty)
; return (mkHsWrapPat wrap res_pat pat_ty, res) }
checkFixedRuntimeRep :: DataCon -> [Scaled TcSigmaTypeFRR] -> TcM ()
checkFixedRuntimeRep :: DataCon -> [Scaled Type] -> TcM ()
checkFixedRuntimeRep DataCon
data_con [Scaled Type]
arg_tys
= (Int -> Scaled Type -> TcM ()) -> [Int] -> [Scaled Type] -> TcM ()
forall (m :: * -> *) a b c.
Applicative m =>
(a -> b -> m c) -> [a] -> [b] -> m ()
zipWithM_ Int -> Scaled Type -> TcM ()
check_one [Int
1..] [Scaled Type]
arg_tys
where
check_one :: Int -> Scaled Type -> TcM ()
check_one Int
i Scaled Type
arg_ty = HasDebugCallStack => FixedRuntimeRepContext -> Type -> TcM ()
FixedRuntimeRepContext -> Type -> TcM ()
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 { pat_ty <- ExpSigmaTypeFRR -> TcM Type
expTypeToType ExpSigmaTypeFRR
pat_ty
; (wrap, pat_rho) <- topInstantiate orig pat_ty
; (co, res) <- inner_match pat_rho
; traceTc "matchExpectedPatTy" (ppr pat_ty $$ ppr wrap)
; return (mkWpCastN (mkSymCo co) <.> wrap, 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 { pat_ty <- ExpSigmaTypeFRR -> TcM Type
expTypeToType (Scaled ExpSigmaTypeFRR -> ExpSigmaTypeFRR
forall a. Scaled a -> a
scaledThing Scaled ExpSigmaTypeFRR
exp_pat_ty)
; (wrap, pat_rho) <- topInstantiate orig pat_ty
; (subst, tvs') <- newMetaTyVars (tyConTyVars data_tc)
; traceTc "matchExpectedConTy" (vcat [ppr data_tc,
ppr (tyConTyVars data_tc),
ppr fam_tc, ppr fam_args,
ppr exp_pat_ty,
ppr pat_ty,
ppr pat_rho, ppr wrap])
; co1 <- unifyType Nothing (mkTyConApp fam_tc (substTys subst fam_args)) pat_rho
; let tys' = [TyCoVar] -> [Type]
mkTyVarTys [TyCoVar]
tvs'
co2 = Role
-> CoAxiom Unbranched -> [Type] -> [TcCoercionN] -> TcCoercionN
mkUnbranchedAxInstCo Role
Representational CoAxiom Unbranched
co_tc [Type]
tys' []
full_co = HasDebugCallStack => TcCoercionN -> TcCoercionN
TcCoercionN -> TcCoercionN
mkSubCo (TcCoercionN -> TcCoercionN
mkSymCo TcCoercionN
co1) HasDebugCallStack => TcCoercionN -> TcCoercionN -> TcCoercionN
TcCoercionN -> TcCoercionN -> TcCoercionN
`mkTransCo` TcCoercionN
co2
; return ( mkWpCastR full_co <.> wrap, tys') }
| Bool
otherwise
= do { pat_ty <- ExpSigmaTypeFRR -> TcM Type
expTypeToType (Scaled ExpSigmaTypeFRR -> ExpSigmaTypeFRR
forall a. Scaled a -> a
scaledThing Scaled ExpSigmaTypeFRR
exp_pat_ty)
; (wrap, pat_rho) <- topInstantiate orig pat_ty
; (coi, tys) <- matchExpectedTyConApp data_tc pat_rho
; return (mkWpCastN (mkSymCo coi) <.> wrap, tys) }
tcConValArgs :: ConLike
-> [Scaled TcSigmaTypeFRR]
-> Checker (HsConPatDetails GhcRn) (HsConPatDetails GhcTc)
tcConValArgs :: ConLike
-> [Scaled Type]
-> Checker
(HsConDetails
(HsConPatTyArg (NoGhcTc GhcRn))
(LPat GhcRn)
(HsRecFields GhcRn (LPat GhcRn)))
(HsConPatDetails GhcTc)
tcConValArgs ConLike
con_like [Scaled Type]
arg_tys PatEnv
penv HsConDetails
(HsConPatTyArg (NoGhcTc GhcRn))
(LPat GhcRn)
(HsRecFields GhcRn (LPat GhcRn))
con_args TcM r
thing_inside = case HsConDetails
(HsConPatTyArg (NoGhcTc GhcRn))
(LPat GhcRn)
(HsRecFields GhcRn (LPat GhcRn))
con_args of
PrefixCon [HsConPatTyArg (NoGhcTc GhcRn)]
type_args [LPat GhcRn]
arg_pats -> do
{ Bool -> TcRnMessage -> TcM ()
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
; (arg_pats', 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
; return (PrefixCon type_args arg_pats', 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 -> TcM ()
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
; ([p1',p2'], 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
; return (InfixCon p1' p2', res) }
where
con_arity :: Int
con_arity = ConLike -> Int
conLikeArity ConLike
con_like
RecCon (HsRecFields XHsRecFields GhcRn
x [LHsRecField GhcRn (LPat GhcRn)]
rpats Maybe (XRec GhcRn RecFieldsDotDot)
dd) -> do
{ TcM ()
check_omitted_fields_multiplicity
; (rpats', res) <- Checker
(GenLocated
SrcSpanAnnA
(HsFieldBind
(GenLocated SrcSpanAnnA (FieldOcc GhcRn))
(GenLocated SrcSpanAnnA (Pat GhcRn))))
(GenLocated
SrcSpanAnnA
(HsFieldBind
(GenLocated SrcSpanAnnA (FieldOcc GhcTc))
(GenLocated SrcSpanAnnA (Pat GhcTc))))
-> Checker
[GenLocated
SrcSpanAnnA
(HsFieldBind
(GenLocated SrcSpanAnnA (FieldOcc GhcRn))
(GenLocated SrcSpanAnnA (Pat GhcRn)))]
[GenLocated
SrcSpanAnnA
(HsFieldBind
(GenLocated SrcSpanAnnA (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 SrcSpanAnnA (FieldOcc GhcRn))
(GenLocated SrcSpanAnnA (Pat GhcRn)))
-> TcM r
-> IOEnv
(Env TcGblEnv TcLclEnv)
(GenLocated
SrcSpanAnnA
(HsFieldBind
(GenLocated SrcSpanAnnA (FieldOcc GhcTc))
(GenLocated SrcSpanAnnA (Pat GhcTc))),
r)
Checker
(LHsRecField GhcRn (LPat GhcRn)) (LHsRecField GhcTc (LPat GhcTc))
Checker
(GenLocated
SrcSpanAnnA
(HsFieldBind
(GenLocated SrcSpanAnnA (FieldOcc GhcRn))
(GenLocated SrcSpanAnnA (Pat GhcRn))))
(GenLocated
SrcSpanAnnA
(HsFieldBind
(GenLocated SrcSpanAnnA (FieldOcc GhcTc))
(GenLocated SrcSpanAnnA (Pat GhcTc))))
tc_field PatEnv
penv [LHsRecField GhcRn (LPat GhcRn)]
[GenLocated
SrcSpanAnnA
(HsFieldBind
(GenLocated SrcSpanAnnA (FieldOcc GhcRn))
(GenLocated SrcSpanAnnA (Pat GhcRn)))]
rpats TcM r
thing_inside
; return ((RecCon (HsRecFields x rpats' dd)), 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 SrcSpanAnnA (FieldOcc GhcRn))
ann (L SrcSpanAnnA
loc (FieldOcc XCFieldOcc GhcRn
rdr (L SrcSpanAnnN
lr Name
sel))) GenLocated SrcSpanAnnA (Pat GhcRn)
pat Bool
pun))
TcM r
thing_inside
= do { sel' <- Name -> TcM TyCoVar
tcLookupId Name
sel
; pat_ty <- setSrcSpanA loc $ find_field_ty sel
(occNameFS $ rdrNameOcc rdr)
; (pat', res) <- tcConArg penv (pat, pat_ty) thing_inside
; return (L l (HsFieldBind ann (L loc (FieldOcc rdr (L lr sel'))) pat'
pun), res) }
check_omitted_fields_multiplicity :: TcM ()
check_omitted_fields_multiplicity :: TcM ()
check_omitted_fields_multiplicity = do
[(Maybe FieldLabel, Scaled Type)]
-> ((Maybe FieldLabel, Scaled Type) -> TcM ()) -> TcM ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
t a -> (a -> m b) -> m ()
forM_ [(Maybe FieldLabel, Scaled Type)]
omitted_field_tys (((Maybe FieldLabel, Scaled Type) -> TcM ()) -> TcM ())
-> ((Maybe FieldLabel, Scaled Type) -> TcM ()) -> TcM ()
forall a b. (a -> b) -> a -> b
$ \(Maybe FieldLabel
fl, Scaled Type
pat_ty) ->
CtOrigin -> Type -> Type -> TcM ()
tcSubMult (Maybe FieldLabel -> CtOrigin
OmittedFieldOrigin Maybe FieldLabel
fl) Type
ManyTy (Scaled Type -> Type
forall a. Scaled a -> Type
scaledMult Scaled Type
pat_ty)
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 | (Just FieldLabel
fl, Scaled Type
ty) <- [(Maybe FieldLabel, Scaled Type)]
bound_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 -> TcM ()
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)
bound_field_tys, omitted_field_tys :: [(Maybe FieldLabel, Scaled TcType)]
([(Maybe FieldLabel, Scaled Type)]
bound_field_tys, [(Maybe FieldLabel, Scaled Type)]
omitted_field_tys) = ((Maybe FieldLabel, Scaled Type) -> Bool)
-> [(Maybe FieldLabel, Scaled Type)]
-> ([(Maybe FieldLabel, Scaled Type)],
[(Maybe FieldLabel, Scaled Type)])
forall a. (a -> Bool) -> [a] -> ([a], [a])
partition (Maybe FieldLabel, Scaled Type) -> Bool
is_bound [(Maybe FieldLabel, Scaled Type)]
all_field_tys
is_bound :: (Maybe FieldLabel, Scaled TcType) -> Bool
is_bound :: (Maybe FieldLabel, Scaled Type) -> Bool
is_bound (Just FieldLabel
fl, Scaled Type
_) = Name -> [Name] -> Bool
forall a. Eq a => a -> [a] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
elem (FieldLabel -> Name
flSelector FieldLabel
fl) ((GenLocated
SrcSpanAnnA
(HsFieldBind
(GenLocated SrcSpanAnnA (FieldOcc GhcRn))
(GenLocated SrcSpanAnnA (Pat GhcRn)))
-> Name)
-> [GenLocated
SrcSpanAnnA
(HsFieldBind
(GenLocated SrcSpanAnnA (FieldOcc GhcRn))
(GenLocated SrcSpanAnnA (Pat GhcRn)))]
-> [Name]
forall a b. (a -> b) -> [a] -> [b]
map (\(L SrcSpanAnnA
_ (HsFieldBind XHsFieldBind (GenLocated SrcSpanAnnA (FieldOcc GhcRn))
_ (L SrcSpanAnnA
_ (FieldOcc XCFieldOcc GhcRn
_ LIdP GhcRn
sel )) GenLocated SrcSpanAnnA (Pat GhcRn)
_ Bool
_)) -> GenLocated SrcSpanAnnN Name -> Name
forall l e. GenLocated l e -> e
unLoc LIdP GhcRn
GenLocated SrcSpanAnnN Name
sel) [LHsRecField GhcRn (LPat GhcRn)]
[GenLocated
SrcSpanAnnA
(HsFieldBind
(GenLocated SrcSpanAnnA (FieldOcc GhcRn))
(GenLocated SrcSpanAnnA (Pat GhcRn)))]
rpats)
is_bound (Maybe FieldLabel, Scaled Type)
_ = Bool
False
all_field_tys :: [(Maybe FieldLabel, Scaled TcType)]
all_field_tys :: [(Maybe FieldLabel, Scaled Type)]
all_field_tys = [Maybe FieldLabel]
-> [Scaled Type] -> [(Maybe FieldLabel, Scaled Type)]
forall a b. [a] -> [b] -> [(a, b)]
zip [Maybe FieldLabel]
con_field_labels [Scaled Type]
arg_tys
con_field_labels :: [Maybe FieldLabel]
con_field_labels :: [Maybe FieldLabel]
con_field_labels = ((FieldLabel -> Maybe FieldLabel)
-> [FieldLabel] -> [Maybe FieldLabel]
forall a b. (a -> b) -> [a] -> [b]
map FieldLabel -> Maybe FieldLabel
forall a. a -> Maybe a
Just (ConLike -> [FieldLabel]
conLikeFieldLabels ConLike
con_like)) [Maybe FieldLabel] -> [Maybe FieldLabel] -> [Maybe FieldLabel]
forall a. [a] -> [a] -> [a]
++ Maybe FieldLabel -> [Maybe FieldLabel]
forall a. a -> [a]
repeat Maybe FieldLabel
forall a. Maybe a
Nothing
splitConTyArgs :: ConLike -> HsConPatDetails GhcRn
-> TcM ( [(HsConPatTyArg GhcRn, TyVar)]
, [(HsConPatTyArg GhcRn, TyVar)] )
splitConTyArgs :: ConLike
-> HsConDetails
(HsConPatTyArg (NoGhcTc GhcRn))
(LPat GhcRn)
(HsRecFields GhcRn (LPat GhcRn))
-> TcM
([(HsConPatTyArg GhcRn, TyCoVar)],
[(HsConPatTyArg GhcRn, TyCoVar)])
splitConTyArgs ConLike
con_like (PrefixCon [HsConPatTyArg (NoGhcTc GhcRn)]
type_args [LPat GhcRn]
_)
= do { Bool -> TcRnMessage -> TcM ()
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 XConPatTyArg GhcRn
_ HsTyPat GhcRn
rn_ty, TyCoVar
con_tv) TcM r
thing_inside
= do { (sig_wcs, sig_ibs, arg_ty) <- HsTyPat GhcRn
-> Type -> TcM ([(Name, TyCoVar)], [(Name, TyCoVar)], Type)
tcHsTyPat HsTyPat GhcRn
rn_ty (HasDebugCallStack => Subst -> Type -> Type
Subst -> Type -> Type
substTy Subst
tenv (TyCoVar -> Type
varType TyCoVar
con_tv))
; case NE.nonEmpty sig_ibs of
Just NonEmpty (Name, TyCoVar)
sig_ibs_ne | PatEnv -> Bool
inPatBind PatEnv
penv ->
TcRnMessage -> TcM ()
addErr (NonEmpty (Name, TyCoVar) -> TcRnMessage
TcRnCannotBindTyVarsInPatBind NonEmpty (Name, TyCoVar)
sig_ibs_ne)
Maybe (NonEmpty (Name, TyCoVar))
_ -> () -> TcM ()
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (f :: * -> *) a. Applicative f => a -> f a
pure ()
; _ <- unifyType Nothing arg_ty (substTyVar tenv con_tv)
; result <- tcExtendNameTyVarEnv sig_wcs $
tcExtendNameTyVarEnv sig_ibs $
thing_inside
; return ((), 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] -> TcM ()
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 = () -> TcM ()
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return ()
| Bool
otherwise = CtOrigin -> [Type] -> TcM ()
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 -> TcM ()
checkGADT ConLike
conlike [TyCoVar]
ex_tvs [Type]
arg_tys = \case
PE { pe_ctxt :: PatEnv -> PatCtxt
pe_ctxt = LetPat {} }
-> () -> TcM ()
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 -> TcM ()
forall a. TcRnMessage -> TcRn a
failWithTc TcRnMessage
TcRnArrowProcGADTPattern
PE { pe_lazy :: PatEnv -> Bool
pe_lazy = Bool
True }
| Bool
has_existentials
-> TcRnMessage -> TcM ()
forall a. TcRnMessage -> TcRn a
failWithTc TcRnMessage
TcRnLazyGADTPattern
PatEnv
_ -> () -> TcM ()
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