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