{-# LANGUAGE CPP, RankNTypes, TupleSections #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE ViewPatterns #-}
module TcPat ( tcLetPat, newLetBndr, LetBndrSpec(..)
, tcPat, tcPat_O, tcPats
, addDataConStupidTheta, badFieldCon, polyPatSig ) where
#include "HsVersions.h"
import GhcPrelude
import {-# SOURCE #-} TcExpr( tcSyntaxOp, tcSyntaxOpGen, tcInferSigma )
import HsSyn
import TcHsSyn
import TcSigs( TcPragEnv, lookupPragEnv, addInlinePrags )
import TcRnMonad
import Inst
import Id
import Var
import Name
import RdrName
import TcEnv
import TcMType
import TcValidity( arityErr )
import Type ( pprTyVars )
import TcType
import TcUnify
import TcHsType
import TysWiredIn
import TcEvidence
import TyCon
import DataCon
import PatSyn
import ConLike
import PrelNames
import BasicTypes hiding (SuccessFlag(..))
import DynFlags
import SrcLoc
import VarSet
import Util
import Outputable
import qualified GHC.LanguageExtensions as LangExt
import Control.Arrow ( second )
import ListSetOps ( getNth )
tcLetPat :: (Name -> Maybe TcId)
-> LetBndrSpec
-> LPat GhcRn -> ExpSigmaType
-> TcM a
-> TcM (LPat GhcTcId, a)
tcLetPat :: (Name -> Maybe TcId)
-> LetBndrSpec
-> LPat GhcRn
-> ExpSigmaType
-> TcM a
-> TcM (LPat GhcTcId, a)
tcLetPat sig_fn :: Name -> Maybe TcId
sig_fn no_gen :: LetBndrSpec
no_gen pat :: LPat GhcRn
pat pat_ty :: ExpSigmaType
pat_ty thing_inside :: TcM a
thing_inside
= do { TcLevel
bind_lvl <- TcM TcLevel
getTcLevel
; let ctxt :: PatCtxt
ctxt = LetPat :: TcLevel -> (Name -> Maybe TcId) -> LetBndrSpec -> PatCtxt
LetPat { pc_lvl :: TcLevel
pc_lvl = TcLevel
bind_lvl
, pc_sig_fn :: Name -> Maybe TcId
pc_sig_fn = Name -> Maybe TcId
sig_fn
, pc_new :: LetBndrSpec
pc_new = LetBndrSpec
no_gen }
penv :: PatEnv
penv = PE :: Bool -> PatCtxt -> CtOrigin -> PatEnv
PE { pe_lazy :: Bool
pe_lazy = Bool
True
, pe_ctxt :: PatCtxt
pe_ctxt = PatCtxt
ctxt
, pe_orig :: CtOrigin
pe_orig = CtOrigin
PatOrigin }
; LPat GhcRn
-> ExpSigmaType -> PatEnv -> TcM a -> TcM (LPat GhcTcId, a)
forall a.
LPat GhcRn
-> ExpSigmaType -> PatEnv -> TcM a -> TcM (LPat GhcTcId, a)
tc_lpat LPat GhcRn
pat ExpSigmaType
pat_ty PatEnv
penv TcM a
thing_inside }
tcPats :: HsMatchContext Name
-> [LPat GhcRn]
-> [ExpSigmaType]
-> TcM a
-> TcM ([LPat GhcTcId], a)
tcPats :: HsMatchContext Name
-> [LPat GhcRn]
-> [ExpSigmaType]
-> TcM a
-> TcM ([LPat GhcTcId], a)
tcPats ctxt :: HsMatchContext Name
ctxt pats :: [LPat GhcRn]
pats pat_tys :: [ExpSigmaType]
pat_tys thing_inside :: TcM a
thing_inside
= PatEnv
-> [LPat GhcRn]
-> [ExpSigmaType]
-> TcM a
-> TcM ([LPat GhcTcId], a)
forall a.
PatEnv
-> [LPat GhcRn]
-> [ExpSigmaType]
-> TcM a
-> TcM ([LPat GhcTcId], a)
tc_lpats PatEnv
penv [LPat GhcRn]
pats [ExpSigmaType]
pat_tys TcM a
thing_inside
where
penv :: PatEnv
penv = PE :: Bool -> PatCtxt -> CtOrigin -> PatEnv
PE { pe_lazy :: Bool
pe_lazy = Bool
False, pe_ctxt :: PatCtxt
pe_ctxt = HsMatchContext Name -> PatCtxt
LamPat HsMatchContext Name
ctxt, pe_orig :: CtOrigin
pe_orig = CtOrigin
PatOrigin }
tcPat :: HsMatchContext Name
-> LPat GhcRn -> ExpSigmaType
-> TcM a
-> TcM (LPat GhcTcId, a)
tcPat :: HsMatchContext Name
-> LPat GhcRn -> ExpSigmaType -> TcM a -> TcM (LPat GhcTcId, a)
tcPat ctxt :: HsMatchContext Name
ctxt = HsMatchContext Name
-> CtOrigin
-> LPat GhcRn
-> ExpSigmaType
-> TcM a
-> TcM (LPat GhcTcId, a)
forall a.
HsMatchContext Name
-> CtOrigin
-> LPat GhcRn
-> ExpSigmaType
-> TcM a
-> TcM (LPat GhcTcId, a)
tcPat_O HsMatchContext Name
ctxt CtOrigin
PatOrigin
tcPat_O :: HsMatchContext Name
-> CtOrigin
-> LPat GhcRn -> ExpSigmaType
-> TcM a
-> TcM (LPat GhcTcId, a)
tcPat_O :: HsMatchContext Name
-> CtOrigin
-> LPat GhcRn
-> ExpSigmaType
-> TcM a
-> TcM (LPat GhcTcId, a)
tcPat_O ctxt :: HsMatchContext Name
ctxt orig :: CtOrigin
orig pat :: LPat GhcRn
pat pat_ty :: ExpSigmaType
pat_ty thing_inside :: TcM a
thing_inside
= LPat GhcRn
-> ExpSigmaType -> PatEnv -> TcM a -> TcM (LPat GhcTcId, a)
forall a.
LPat GhcRn
-> ExpSigmaType -> PatEnv -> TcM a -> TcM (LPat GhcTcId, a)
tc_lpat LPat GhcRn
pat ExpSigmaType
pat_ty PatEnv
penv TcM a
thing_inside
where
penv :: PatEnv
penv = PE :: Bool -> PatCtxt -> CtOrigin -> PatEnv
PE { pe_lazy :: Bool
pe_lazy = Bool
False, pe_ctxt :: PatCtxt
pe_ctxt = HsMatchContext Name -> PatCtxt
LamPat HsMatchContext Name
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 Name)
| LetPat
{ PatCtxt -> TcLevel
pc_lvl :: TcLevel
, PatCtxt -> Name -> Maybe TcId
pc_sig_fn :: Name -> Maybe TcId
, PatCtxt -> LetBndrSpec
pc_new :: LetBndrSpec
}
data LetBndrSpec
= LetLclBndr
| LetGblBndr TcPragEnv
instance Outputable LetBndrSpec where
ppr :: LetBndrSpec -> SDoc
ppr LetLclBndr = String -> SDoc
text "LetLclBndr"
ppr (LetGblBndr {}) = String -> SDoc
text "LetGblBndr"
makeLazy :: PatEnv -> PatEnv
makeLazy :: PatEnv -> PatEnv
makeLazy penv :: PatEnv
penv = PatEnv
penv { pe_lazy :: Bool
pe_lazy = Bool
True }
inPatBind :: PatEnv -> Bool
inPatBind :: PatEnv -> Bool
inPatBind (PE { pe_ctxt :: PatEnv -> PatCtxt
pe_ctxt = LetPat {} }) = Bool
True
inPatBind (PE { pe_ctxt :: PatEnv -> PatCtxt
pe_ctxt = LamPat {} }) = Bool
False
tcPatBndr :: PatEnv -> Name -> ExpSigmaType -> TcM (HsWrapper, TcId)
tcPatBndr :: PatEnv -> Name -> ExpSigmaType -> TcM (HsWrapper, TcId)
tcPatBndr penv :: PatEnv
penv@(PE { pe_ctxt :: PatEnv -> PatCtxt
pe_ctxt = LetPat { pc_lvl :: PatCtxt -> TcLevel
pc_lvl = TcLevel
bind_lvl
, pc_sig_fn :: PatCtxt -> Name -> Maybe TcId
pc_sig_fn = Name -> Maybe TcId
sig_fn
, pc_new :: PatCtxt -> LetBndrSpec
pc_new = LetBndrSpec
no_gen } })
bndr_name :: Name
bndr_name exp_pat_ty :: ExpSigmaType
exp_pat_ty
| Just bndr_id :: TcId
bndr_id <- Name -> Maybe TcId
sig_fn Name
bndr_name
= do { HsWrapper
wrap <- PatEnv -> ExpSigmaType -> TcSigmaType -> TcM HsWrapper
tcSubTypePat PatEnv
penv ExpSigmaType
exp_pat_ty (TcId -> TcSigmaType
idType TcId
bndr_id)
; String -> SDoc -> TcRn ()
traceTc "tcPatBndr(sig)" (TcId -> SDoc
forall a. Outputable a => a -> SDoc
ppr TcId
bndr_id SDoc -> SDoc -> SDoc
$$ TcSigmaType -> SDoc
forall a. Outputable a => a -> SDoc
ppr (TcId -> TcSigmaType
idType TcId
bndr_id) SDoc -> SDoc -> SDoc
$$ ExpSigmaType -> SDoc
forall a. Outputable a => a -> SDoc
ppr ExpSigmaType
exp_pat_ty)
; (HsWrapper, TcId) -> TcM (HsWrapper, TcId)
forall (m :: * -> *) a. Monad m => a -> m a
return (HsWrapper
wrap, TcId
bndr_id) }
| Bool
otherwise
= do { (co :: TcCoercion
co, bndr_ty :: TcSigmaType
bndr_ty) <- case ExpSigmaType
exp_pat_ty of
Check pat_ty :: TcSigmaType
pat_ty -> TcLevel -> TcSigmaType -> TcM (TcCoercion, TcSigmaType)
promoteTcType TcLevel
bind_lvl TcSigmaType
pat_ty
Infer infer_res :: InferResult
infer_res -> ASSERT( bind_lvl == ir_lvl infer_res )
do { TcSigmaType
bndr_ty <- InferResult -> TcM TcSigmaType
inferResultToType InferResult
infer_res
; (TcCoercion, TcSigmaType) -> TcM (TcCoercion, TcSigmaType)
forall (m :: * -> *) a. Monad m => a -> m a
return (TcSigmaType -> TcCoercion
mkTcNomReflCo TcSigmaType
bndr_ty, TcSigmaType
bndr_ty) }
; TcId
bndr_id <- LetBndrSpec -> Name -> TcSigmaType -> TcM TcId
newLetBndr LetBndrSpec
no_gen Name
bndr_name TcSigmaType
bndr_ty
; String -> SDoc -> TcRn ()
traceTc "tcPatBndr(nosig)" ([SDoc] -> SDoc
vcat [ TcLevel -> SDoc
forall a. Outputable a => a -> SDoc
ppr TcLevel
bind_lvl
, ExpSigmaType -> SDoc
forall a. Outputable a => a -> SDoc
ppr ExpSigmaType
exp_pat_ty, TcSigmaType -> SDoc
forall a. Outputable a => a -> SDoc
ppr TcSigmaType
bndr_ty, TcCoercion -> SDoc
forall a. Outputable a => a -> SDoc
ppr TcCoercion
co
, TcId -> SDoc
forall a. Outputable a => a -> SDoc
ppr TcId
bndr_id ])
; (HsWrapper, TcId) -> TcM (HsWrapper, TcId)
forall (m :: * -> *) a. Monad m => a -> m a
return (TcCoercion -> HsWrapper
mkWpCastN TcCoercion
co, TcId
bndr_id) }
tcPatBndr _ bndr_name :: Name
bndr_name pat_ty :: ExpSigmaType
pat_ty
= do { TcSigmaType
pat_ty <- ExpSigmaType -> TcM TcSigmaType
expTypeToType ExpSigmaType
pat_ty
; String -> SDoc -> TcRn ()
traceTc "tcPatBndr(not let)" (Name -> SDoc
forall a. Outputable a => a -> SDoc
ppr Name
bndr_name SDoc -> SDoc -> SDoc
$$ TcSigmaType -> SDoc
forall a. Outputable a => a -> SDoc
ppr TcSigmaType
pat_ty)
; (HsWrapper, TcId) -> TcM (HsWrapper, TcId)
forall (m :: * -> *) a. Monad m => a -> m a
return (HsWrapper
idHsWrapper, Name -> TcSigmaType -> TcId
mkLocalId Name
bndr_name TcSigmaType
pat_ty) }
newLetBndr :: LetBndrSpec -> Name -> TcType -> TcM TcId
newLetBndr :: LetBndrSpec -> Name -> TcSigmaType -> TcM TcId
newLetBndr LetLclBndr name :: Name
name ty :: TcSigmaType
ty
= do { Name
mono_name <- Name -> TcM Name
cloneLocalName Name
name
; TcId -> TcM TcId
forall (m :: * -> *) a. Monad m => a -> m a
return (Name -> TcSigmaType -> TcId
mkLocalId Name
mono_name TcSigmaType
ty) }
newLetBndr (LetGblBndr prags :: TcPragEnv
prags) name :: Name
name ty :: TcSigmaType
ty
= TcId -> [LSig GhcRn] -> TcM TcId
addInlinePrags (Name -> TcSigmaType -> TcId
mkLocalId Name
name TcSigmaType
ty) (TcPragEnv -> Name -> [LSig GhcRn]
lookupPragEnv TcPragEnv
prags Name
name)
tcSubTypePat :: PatEnv -> ExpSigmaType -> TcSigmaType -> TcM HsWrapper
tcSubTypePat :: PatEnv -> ExpSigmaType -> TcSigmaType -> TcM HsWrapper
tcSubTypePat penv :: PatEnv
penv t1 :: ExpSigmaType
t1 t2 :: TcSigmaType
t2 = CtOrigin
-> UserTypeCtxt -> ExpSigmaType -> TcSigmaType -> TcM HsWrapper
tcSubTypeET (PatEnv -> CtOrigin
pe_orig PatEnv
penv) UserTypeCtxt
GenSigCtxt ExpSigmaType
t1 TcSigmaType
t2
type Checker inp out = forall r.
inp
-> PatEnv
-> TcM r
-> TcM (out, r)
tcMultiple :: Checker inp out -> Checker [inp] [out]
tcMultiple :: Checker inp out -> Checker [inp] [out]
tcMultiple tc_pat :: Checker inp out
tc_pat args :: [inp]
args penv :: PatEnv
penv thing_inside :: TcM r
thing_inside
= do { [ErrCtxt]
err_ctxt <- TcM [ErrCtxt]
getErrCtxt
; let loop :: PatEnv -> [inp] -> TcM ([out], r)
loop _ []
= do { r
res <- TcM r
thing_inside
; ([out], r) -> TcM ([out], r)
forall (m :: * -> *) a. Monad m => a -> m a
return ([], r
res) }
loop penv :: PatEnv
penv (arg :: inp
arg:args :: [inp]
args)
= do { (p' :: out
p', (ps' :: [out]
ps', res :: r
res))
<- inp -> PatEnv -> TcM ([out], r) -> TcM (out, ([out], r))
Checker inp out
tc_pat inp
arg PatEnv
penv (TcM ([out], r) -> TcM (out, ([out], r)))
-> TcM ([out], r) -> TcM (out, ([out], r))
forall a b. (a -> b) -> a -> b
$
[ErrCtxt] -> TcM ([out], r) -> TcM ([out], r)
forall a. [ErrCtxt] -> TcM a -> TcM a
setErrCtxt [ErrCtxt]
err_ctxt (TcM ([out], r) -> TcM ([out], r))
-> TcM ([out], r) -> TcM ([out], r)
forall a b. (a -> b) -> a -> b
$
PatEnv -> [inp] -> TcM ([out], r)
loop PatEnv
penv [inp]
args
; ([out], r) -> TcM ([out], r)
forall (m :: * -> *) a. Monad m => a -> m a
return (out
p'out -> [out] -> [out]
forall a. a -> [a] -> [a]
:[out]
ps', r
res) }
; PatEnv -> [inp] -> TcM ([out], r)
loop PatEnv
penv [inp]
args }
tc_lpat :: LPat GhcRn
-> ExpSigmaType
-> PatEnv
-> TcM a
-> TcM (LPat GhcTcId, a)
tc_lpat :: LPat GhcRn
-> ExpSigmaType -> PatEnv -> TcM a -> TcM (LPat GhcTcId, a)
tc_lpat (LPat GhcRn -> Located (SrcSpanLess (LPat GhcRn))
forall a. HasSrcSpan a => a -> Located (SrcSpanLess a)
dL->L span :: SrcSpan
span pat :: SrcSpanLess (LPat GhcRn)
pat) pat_ty :: ExpSigmaType
pat_ty penv :: PatEnv
penv thing_inside :: TcM a
thing_inside
= SrcSpan -> TcM (LPat GhcTcId, a) -> TcM (LPat GhcTcId, a)
forall a. SrcSpan -> TcRn a -> TcRn a
setSrcSpan SrcSpan
span (TcM (LPat GhcTcId, a) -> TcM (LPat GhcTcId, a))
-> TcM (LPat GhcTcId, a) -> TcM (LPat GhcTcId, a)
forall a b. (a -> b) -> a -> b
$
do { (pat' :: LPat GhcTcId
pat', res :: a
res) <- LPat GhcRn
-> (TcM a -> TcM (LPat GhcTcId, a))
-> TcM a
-> TcM (LPat GhcTcId, a)
forall a b. LPat GhcRn -> (TcM a -> TcM b) -> TcM a -> TcM b
maybeWrapPatCtxt SrcSpanLess (LPat GhcRn)
LPat GhcRn
pat (PatEnv
-> LPat GhcRn -> ExpSigmaType -> TcM a -> TcM (LPat GhcTcId, a)
forall a.
PatEnv
-> LPat GhcRn -> ExpSigmaType -> TcM a -> TcM (LPat GhcTcId, a)
tc_pat PatEnv
penv SrcSpanLess (LPat GhcRn)
LPat GhcRn
pat ExpSigmaType
pat_ty)
TcM a
thing_inside
; (LPat GhcTcId, a) -> TcM (LPat GhcTcId, a)
forall (m :: * -> *) a. Monad m => a -> m a
return (SrcSpan -> SrcSpanLess (LPat GhcTcId) -> LPat GhcTcId
forall a. HasSrcSpan a => SrcSpan -> SrcSpanLess a -> a
cL SrcSpan
span SrcSpanLess (LPat GhcTcId)
LPat GhcTcId
pat', a
res) }
tc_lpats :: PatEnv
-> [LPat GhcRn] -> [ExpSigmaType]
-> TcM a
-> TcM ([LPat GhcTcId], a)
tc_lpats :: PatEnv
-> [LPat GhcRn]
-> [ExpSigmaType]
-> TcM a
-> TcM ([LPat GhcTcId], a)
tc_lpats penv :: PatEnv
penv pats :: [LPat GhcRn]
pats tys :: [ExpSigmaType]
tys thing_inside :: TcM a
thing_inside
= ASSERT2( equalLength pats tys, ppr pats $$ ppr tys )
Checker (LPat GhcRn, ExpSigmaType) (LPat GhcTcId)
-> [(LPat GhcRn, ExpSigmaType)]
-> PatEnv
-> TcM a
-> TcM ([LPat GhcTcId], a)
forall inp out. Checker inp out -> Checker [inp] [out]
tcMultiple (\(p,t) -> LPat GhcRn
-> ExpSigmaType -> PatEnv -> TcM r -> TcM (LPat GhcTcId, r)
forall a.
LPat GhcRn
-> ExpSigmaType -> PatEnv -> TcM a -> TcM (LPat GhcTcId, a)
tc_lpat LPat GhcRn
p ExpSigmaType
t)
(String
-> [LPat GhcRn] -> [ExpSigmaType] -> [(LPat GhcRn, ExpSigmaType)]
forall a b. String -> [a] -> [b] -> [(a, b)]
zipEqual "tc_lpats" [LPat GhcRn]
pats [ExpSigmaType]
tys)
PatEnv
penv TcM a
thing_inside
tc_pat :: PatEnv
-> Pat GhcRn
-> ExpSigmaType
-> TcM a
-> TcM (Pat GhcTcId,
a)
tc_pat :: PatEnv
-> LPat GhcRn -> ExpSigmaType -> TcM a -> TcM (LPat GhcTcId, a)
tc_pat penv :: PatEnv
penv (VarPat x :: XVarPat GhcRn
x (Located (IdP GhcRn) -> Located (SrcSpanLess (Located Name))
forall a. HasSrcSpan a => a -> Located (SrcSpanLess a)
dL->L l :: SrcSpan
l name :: SrcSpanLess (Located Name)
name)) pat_ty :: ExpSigmaType
pat_ty thing_inside :: TcM a
thing_inside
= do { (wrap :: HsWrapper
wrap, id :: TcId
id) <- PatEnv -> Name -> ExpSigmaType -> TcM (HsWrapper, TcId)
tcPatBndr PatEnv
penv Name
SrcSpanLess (Located Name)
name ExpSigmaType
pat_ty
; a
res <- Name -> TcId -> TcM a -> TcM a
forall a. Name -> TcId -> TcM a -> TcM a
tcExtendIdEnv1 Name
SrcSpanLess (Located Name)
name TcId
id TcM a
thing_inside
; TcSigmaType
pat_ty <- ExpSigmaType -> TcM TcSigmaType
readExpType ExpSigmaType
pat_ty
; (LPat GhcTcId, a) -> TcM (LPat GhcTcId, a)
forall (m :: * -> *) a. Monad m => a -> m a
return (HsWrapper -> LPat GhcTcId -> TcSigmaType -> LPat GhcTcId
forall (id :: Pass).
HsWrapper -> Pat (GhcPass id) -> TcSigmaType -> Pat (GhcPass id)
mkHsWrapPat HsWrapper
wrap (XVarPat GhcTcId -> Located (IdP GhcTcId) -> LPat GhcTcId
forall p. XVarPat p -> Located (IdP p) -> Pat p
VarPat XVarPat GhcRn
XVarPat GhcTcId
x (SrcSpan -> SrcSpanLess (Located TcId) -> Located TcId
forall a. HasSrcSpan a => SrcSpan -> SrcSpanLess a -> a
cL SrcSpan
l SrcSpanLess (Located TcId)
TcId
id)) TcSigmaType
pat_ty, a
res) }
tc_pat penv :: PatEnv
penv (ParPat x :: XParPat GhcRn
x pat :: LPat GhcRn
pat) pat_ty :: ExpSigmaType
pat_ty thing_inside :: TcM a
thing_inside
= do { (pat' :: LPat GhcTcId
pat', res :: a
res) <- LPat GhcRn
-> ExpSigmaType -> PatEnv -> TcM a -> TcM (LPat GhcTcId, a)
forall a.
LPat GhcRn
-> ExpSigmaType -> PatEnv -> TcM a -> TcM (LPat GhcTcId, a)
tc_lpat LPat GhcRn
pat ExpSigmaType
pat_ty PatEnv
penv TcM a
thing_inside
; (LPat GhcTcId, a) -> TcM (LPat GhcTcId, a)
forall (m :: * -> *) a. Monad m => a -> m a
return (XParPat GhcTcId -> LPat GhcTcId -> LPat GhcTcId
forall p. XParPat p -> Pat p -> Pat p
ParPat XParPat GhcRn
XParPat GhcTcId
x LPat GhcTcId
pat', a
res) }
tc_pat penv :: PatEnv
penv (BangPat x :: XBangPat GhcRn
x pat :: LPat GhcRn
pat) pat_ty :: ExpSigmaType
pat_ty thing_inside :: TcM a
thing_inside
= do { (pat' :: LPat GhcTcId
pat', res :: a
res) <- LPat GhcRn
-> ExpSigmaType -> PatEnv -> TcM a -> TcM (LPat GhcTcId, a)
forall a.
LPat GhcRn
-> ExpSigmaType -> PatEnv -> TcM a -> TcM (LPat GhcTcId, a)
tc_lpat LPat GhcRn
pat ExpSigmaType
pat_ty PatEnv
penv TcM a
thing_inside
; (LPat GhcTcId, a) -> TcM (LPat GhcTcId, a)
forall (m :: * -> *) a. Monad m => a -> m a
return (XBangPat GhcTcId -> LPat GhcTcId -> LPat GhcTcId
forall p. XBangPat p -> Pat p -> Pat p
BangPat XBangPat GhcRn
XBangPat GhcTcId
x LPat GhcTcId
pat', a
res) }
tc_pat penv :: PatEnv
penv (LazyPat x :: XLazyPat GhcRn
x pat :: LPat GhcRn
pat) pat_ty :: ExpSigmaType
pat_ty thing_inside :: TcM a
thing_inside
= do { (pat' :: LPat GhcTcId
pat', (res :: a
res, pat_ct :: WantedConstraints
pat_ct))
<- LPat GhcRn
-> ExpSigmaType
-> PatEnv
-> TcM (a, WantedConstraints)
-> TcM (LPat GhcTcId, (a, WantedConstraints))
forall a.
LPat GhcRn
-> ExpSigmaType -> PatEnv -> TcM a -> TcM (LPat GhcTcId, a)
tc_lpat LPat GhcRn
pat ExpSigmaType
pat_ty (PatEnv -> PatEnv
makeLazy PatEnv
penv) (TcM (a, WantedConstraints)
-> TcM (LPat GhcTcId, (a, WantedConstraints)))
-> TcM (a, WantedConstraints)
-> TcM (LPat GhcTcId, (a, WantedConstraints))
forall a b. (a -> b) -> a -> b
$
TcM a -> TcM (a, WantedConstraints)
forall a. TcM a -> TcM (a, WantedConstraints)
captureConstraints TcM a
thing_inside
; WantedConstraints -> TcRn ()
emitConstraints WantedConstraints
pat_ct
; TcSigmaType
pat_ty <- ExpSigmaType -> TcM TcSigmaType
readExpType ExpSigmaType
pat_ty
; TcCoercion
_ <- Maybe (HsExpr GhcRn)
-> TcSigmaType -> TcSigmaType -> TcM TcCoercion
unifyType Maybe (HsExpr GhcRn)
forall a. Maybe a
Nothing (HasDebugCallStack => TcSigmaType -> TcSigmaType
TcSigmaType -> TcSigmaType
tcTypeKind TcSigmaType
pat_ty) TcSigmaType
liftedTypeKind
; (LPat GhcTcId, a) -> TcM (LPat GhcTcId, a)
forall (m :: * -> *) a. Monad m => a -> m a
return (XLazyPat GhcTcId -> LPat GhcTcId -> LPat GhcTcId
forall p. XLazyPat p -> Pat p -> Pat p
LazyPat XLazyPat GhcRn
XLazyPat GhcTcId
x LPat GhcTcId
pat', a
res) }
tc_pat _ (WildPat _) pat_ty :: ExpSigmaType
pat_ty thing_inside :: TcM a
thing_inside
= do { a
res <- TcM a
thing_inside
; TcSigmaType
pat_ty <- ExpSigmaType -> TcM TcSigmaType
expTypeToType ExpSigmaType
pat_ty
; (LPat GhcTcId, a) -> TcM (LPat GhcTcId, a)
forall (m :: * -> *) a. Monad m => a -> m a
return (XWildPat GhcTcId -> LPat GhcTcId
forall p. XWildPat p -> Pat p
WildPat TcSigmaType
XWildPat GhcTcId
pat_ty, a
res) }
tc_pat penv :: PatEnv
penv (AsPat x :: XAsPat GhcRn
x (Located (IdP GhcRn) -> Located (SrcSpanLess (Located Name))
forall a. HasSrcSpan a => a -> Located (SrcSpanLess a)
dL->L nm_loc :: SrcSpan
nm_loc name :: SrcSpanLess (Located Name)
name) pat :: LPat GhcRn
pat) pat_ty :: ExpSigmaType
pat_ty thing_inside :: TcM a
thing_inside
= do { (wrap :: HsWrapper
wrap, bndr_id :: TcId
bndr_id) <- SrcSpan -> TcM (HsWrapper, TcId) -> TcM (HsWrapper, TcId)
forall a. SrcSpan -> TcRn a -> TcRn a
setSrcSpan SrcSpan
nm_loc (PatEnv -> Name -> ExpSigmaType -> TcM (HsWrapper, TcId)
tcPatBndr PatEnv
penv Name
SrcSpanLess (Located Name)
name ExpSigmaType
pat_ty)
; (pat' :: LPat GhcTcId
pat', res :: a
res) <- Name -> TcId -> TcM (LPat GhcTcId, a) -> TcM (LPat GhcTcId, a)
forall a. Name -> TcId -> TcM a -> TcM a
tcExtendIdEnv1 Name
SrcSpanLess (Located Name)
name TcId
bndr_id (TcM (LPat GhcTcId, a) -> TcM (LPat GhcTcId, a))
-> TcM (LPat GhcTcId, a) -> TcM (LPat GhcTcId, a)
forall a b. (a -> b) -> a -> b
$
LPat GhcRn
-> ExpSigmaType -> PatEnv -> TcM a -> TcM (LPat GhcTcId, a)
forall a.
LPat GhcRn
-> ExpSigmaType -> PatEnv -> TcM a -> TcM (LPat GhcTcId, a)
tc_lpat LPat GhcRn
pat (TcSigmaType -> ExpSigmaType
mkCheckExpType (TcSigmaType -> ExpSigmaType) -> TcSigmaType -> ExpSigmaType
forall a b. (a -> b) -> a -> b
$ TcId -> TcSigmaType
idType TcId
bndr_id)
PatEnv
penv TcM a
thing_inside
; TcSigmaType
pat_ty <- ExpSigmaType -> TcM TcSigmaType
readExpType ExpSigmaType
pat_ty
; (LPat GhcTcId, a) -> TcM (LPat GhcTcId, a)
forall (m :: * -> *) a. Monad m => a -> m a
return (HsWrapper -> LPat GhcTcId -> TcSigmaType -> LPat GhcTcId
forall (id :: Pass).
HsWrapper -> Pat (GhcPass id) -> TcSigmaType -> Pat (GhcPass id)
mkHsWrapPat HsWrapper
wrap (XAsPat GhcTcId
-> Located (IdP GhcTcId) -> LPat GhcTcId -> LPat GhcTcId
forall p. XAsPat p -> Located (IdP p) -> Pat p -> Pat p
AsPat XAsPat GhcRn
XAsPat GhcTcId
x (SrcSpan -> SrcSpanLess (Located TcId) -> Located TcId
forall a. HasSrcSpan a => SrcSpan -> SrcSpanLess a -> a
cL SrcSpan
nm_loc SrcSpanLess (Located TcId)
TcId
bndr_id) LPat GhcTcId
pat') TcSigmaType
pat_ty,
a
res) }
tc_pat penv :: PatEnv
penv (ViewPat _ expr :: LHsExpr GhcRn
expr pat :: LPat GhcRn
pat) overall_pat_ty :: ExpSigmaType
overall_pat_ty thing_inside :: TcM a
thing_inside
= do {
; (expr' :: LHsExpr GhcTcId
expr',expr'_inferred :: TcSigmaType
expr'_inferred) <- LHsExpr GhcRn -> TcM (LHsExpr GhcTcId, TcSigmaType)
tcInferSigma LHsExpr GhcRn
expr
; let expr_orig :: CtOrigin
expr_orig = LHsExpr GhcRn -> CtOrigin
lexprCtOrigin LHsExpr GhcRn
expr
herald :: SDoc
herald = String -> SDoc
text "A view pattern expression expects"
; (expr_wrap1 :: HsWrapper
expr_wrap1, [inf_arg_ty :: TcSigmaType
inf_arg_ty], inf_res_ty :: TcSigmaType
inf_res_ty)
<- SDoc
-> CtOrigin
-> Maybe (HsExpr GhcRn)
-> Int
-> TcSigmaType
-> TcM (HsWrapper, [TcSigmaType], TcSigmaType)
matchActualFunTys SDoc
herald CtOrigin
expr_orig (HsExpr GhcRn -> Maybe (HsExpr GhcRn)
forall a. a -> Maybe a
Just (LHsExpr GhcRn -> SrcSpanLess (LHsExpr GhcRn)
forall a. HasSrcSpan a => a -> SrcSpanLess a
unLoc LHsExpr GhcRn
expr)) 1 TcSigmaType
expr'_inferred
; HsWrapper
expr_wrap2 <- PatEnv -> ExpSigmaType -> TcSigmaType -> TcM HsWrapper
tcSubTypePat PatEnv
penv ExpSigmaType
overall_pat_ty TcSigmaType
inf_arg_ty
; (pat' :: LPat GhcTcId
pat', res :: a
res) <- LPat GhcRn
-> ExpSigmaType -> PatEnv -> TcM a -> TcM (LPat GhcTcId, a)
forall a.
LPat GhcRn
-> ExpSigmaType -> PatEnv -> TcM a -> TcM (LPat GhcTcId, a)
tc_lpat LPat GhcRn
pat (TcSigmaType -> ExpSigmaType
mkCheckExpType TcSigmaType
inf_res_ty) PatEnv
penv TcM a
thing_inside
; TcSigmaType
overall_pat_ty <- ExpSigmaType -> TcM TcSigmaType
readExpType ExpSigmaType
overall_pat_ty
; let expr_wrap2' :: HsWrapper
expr_wrap2' = HsWrapper
-> HsWrapper -> TcSigmaType -> TcSigmaType -> SDoc -> HsWrapper
mkWpFun HsWrapper
expr_wrap2 HsWrapper
idHsWrapper
TcSigmaType
overall_pat_ty TcSigmaType
inf_res_ty SDoc
doc
expr_wrap :: HsWrapper
expr_wrap = HsWrapper
expr_wrap2' HsWrapper -> HsWrapper -> HsWrapper
<.> HsWrapper
expr_wrap1
doc :: SDoc
doc = String -> SDoc
text "When checking the view pattern function:" SDoc -> SDoc -> SDoc
<+> (LHsExpr GhcRn -> SDoc
forall a. Outputable a => a -> SDoc
ppr LHsExpr GhcRn
expr)
; (LPat GhcTcId, a) -> TcM (LPat GhcTcId, a)
forall (m :: * -> *) a. Monad m => a -> m a
return (XViewPat GhcTcId -> LHsExpr GhcTcId -> LPat GhcTcId -> LPat GhcTcId
forall p. XViewPat p -> LHsExpr p -> Pat p -> Pat p
ViewPat TcSigmaType
XViewPat GhcTcId
overall_pat_ty (HsWrapper -> LHsExpr GhcTcId -> LHsExpr GhcTcId
forall (id :: Pass).
HsWrapper -> LHsExpr (GhcPass id) -> LHsExpr (GhcPass id)
mkLHsWrap HsWrapper
expr_wrap LHsExpr GhcTcId
expr') LPat GhcTcId
pat', a
res)}
tc_pat penv :: PatEnv
penv (SigPat _ pat :: LPat GhcRn
pat sig_ty :: LHsSigWcType (NoGhcTc GhcRn)
sig_ty) pat_ty :: ExpSigmaType
pat_ty thing_inside :: TcM a
thing_inside
= do { (inner_ty :: TcSigmaType
inner_ty, tv_binds :: [(Name, TcId)]
tv_binds, wcs :: [(Name, TcId)]
wcs, wrap :: HsWrapper
wrap) <- Bool
-> LHsSigWcType GhcRn
-> ExpSigmaType
-> TcM (TcSigmaType, [(Name, TcId)], [(Name, TcId)], HsWrapper)
tcPatSig (PatEnv -> Bool
inPatBind PatEnv
penv)
LHsSigWcType (NoGhcTc GhcRn)
LHsSigWcType GhcRn
sig_ty ExpSigmaType
pat_ty
; (pat' :: LPat GhcTcId
pat', res :: a
res) <- [(Name, TcId)] -> TcM (LPat GhcTcId, a) -> TcM (LPat GhcTcId, a)
forall r. [(Name, TcId)] -> TcM r -> TcM r
tcExtendNameTyVarEnv [(Name, TcId)]
wcs (TcM (LPat GhcTcId, a) -> TcM (LPat GhcTcId, a))
-> TcM (LPat GhcTcId, a) -> TcM (LPat GhcTcId, a)
forall a b. (a -> b) -> a -> b
$
[(Name, TcId)] -> TcM (LPat GhcTcId, a) -> TcM (LPat GhcTcId, a)
forall r. [(Name, TcId)] -> TcM r -> TcM r
tcExtendNameTyVarEnv [(Name, TcId)]
tv_binds (TcM (LPat GhcTcId, a) -> TcM (LPat GhcTcId, a))
-> TcM (LPat GhcTcId, a) -> TcM (LPat GhcTcId, a)
forall a b. (a -> b) -> a -> b
$
LPat GhcRn
-> ExpSigmaType -> PatEnv -> TcM a -> TcM (LPat GhcTcId, a)
forall a.
LPat GhcRn
-> ExpSigmaType -> PatEnv -> TcM a -> TcM (LPat GhcTcId, a)
tc_lpat LPat GhcRn
pat (TcSigmaType -> ExpSigmaType
mkCheckExpType TcSigmaType
inner_ty) PatEnv
penv TcM a
thing_inside
; TcSigmaType
pat_ty <- ExpSigmaType -> TcM TcSigmaType
readExpType ExpSigmaType
pat_ty
; (LPat GhcTcId, a) -> TcM (LPat GhcTcId, a)
forall (m :: * -> *) a. Monad m => a -> m a
return (HsWrapper -> LPat GhcTcId -> TcSigmaType -> LPat GhcTcId
forall (id :: Pass).
HsWrapper -> Pat (GhcPass id) -> TcSigmaType -> Pat (GhcPass id)
mkHsWrapPat HsWrapper
wrap (XSigPat GhcTcId
-> LPat GhcTcId -> LHsSigWcType (NoGhcTc GhcTcId) -> LPat GhcTcId
forall p. XSigPat p -> Pat p -> LHsSigWcType (NoGhcTc p) -> Pat p
SigPat TcSigmaType
XSigPat GhcTcId
inner_ty LPat GhcTcId
pat' LHsSigWcType (NoGhcTc GhcRn)
LHsSigWcType (NoGhcTc GhcTcId)
sig_ty) TcSigmaType
pat_ty, a
res) }
tc_pat penv :: PatEnv
penv (ListPat Nothing pats :: [LPat GhcRn]
pats) pat_ty :: ExpSigmaType
pat_ty thing_inside :: TcM a
thing_inside
= do { (coi :: HsWrapper
coi, elt_ty :: TcSigmaType
elt_ty) <- (TcSigmaType -> TcM (TcCoercion, TcSigmaType))
-> PatEnv -> ExpSigmaType -> TcM (HsWrapper, TcSigmaType)
forall a.
(TcSigmaType -> TcM (TcCoercion, a))
-> PatEnv -> ExpSigmaType -> TcM (HsWrapper, a)
matchExpectedPatTy TcSigmaType -> TcM (TcCoercion, TcSigmaType)
matchExpectedListTy PatEnv
penv ExpSigmaType
pat_ty
; (pats' :: [LPat GhcTcId]
pats', res :: a
res) <- Checker (LPat GhcRn) (LPat GhcTcId)
-> [LPat GhcRn] -> PatEnv -> TcM a -> TcM ([LPat GhcTcId], a)
forall inp out. Checker inp out -> Checker [inp] [out]
tcMultiple (\p :: LPat GhcRn
p -> LPat GhcRn
-> ExpSigmaType -> PatEnv -> TcM r -> TcM (LPat GhcTcId, r)
forall a.
LPat GhcRn
-> ExpSigmaType -> PatEnv -> TcM a -> TcM (LPat GhcTcId, a)
tc_lpat LPat GhcRn
p (TcSigmaType -> ExpSigmaType
mkCheckExpType TcSigmaType
elt_ty))
[LPat GhcRn]
pats PatEnv
penv TcM a
thing_inside
; TcSigmaType
pat_ty <- ExpSigmaType -> TcM TcSigmaType
readExpType ExpSigmaType
pat_ty
; (LPat GhcTcId, a) -> TcM (LPat GhcTcId, a)
forall (m :: * -> *) a. Monad m => a -> m a
return (HsWrapper -> LPat GhcTcId -> TcSigmaType -> LPat GhcTcId
forall (id :: Pass).
HsWrapper -> Pat (GhcPass id) -> TcSigmaType -> Pat (GhcPass id)
mkHsWrapPat HsWrapper
coi
(XListPat GhcTcId -> [LPat GhcTcId] -> LPat GhcTcId
forall p. XListPat p -> [Pat p] -> Pat p
ListPat (TcSigmaType -> Maybe (TcSigmaType, SyntaxExpr GhcTcId) -> ListPatTc
ListPatTc TcSigmaType
elt_ty Maybe (TcSigmaType, SyntaxExpr GhcTcId)
forall a. Maybe a
Nothing) [LPat GhcTcId]
pats') TcSigmaType
pat_ty, a
res)
}
tc_pat penv :: PatEnv
penv (ListPat (Just e) pats :: [LPat GhcRn]
pats) pat_ty :: ExpSigmaType
pat_ty thing_inside :: TcM a
thing_inside
= do { TcSigmaType
tau_pat_ty <- ExpSigmaType -> TcM TcSigmaType
expTypeToType ExpSigmaType
pat_ty
; ((pats' :: [LPat GhcTcId]
pats', res :: a
res, elt_ty :: TcSigmaType
elt_ty), e' :: SyntaxExpr GhcTcId
e')
<- CtOrigin
-> SyntaxExpr GhcRn
-> [SyntaxOpType]
-> SyntaxOpType
-> ([TcSigmaType] -> TcM ([LPat GhcTcId], a, TcSigmaType))
-> TcM (([LPat GhcTcId], a, TcSigmaType), SyntaxExpr GhcTcId)
forall a.
CtOrigin
-> SyntaxExpr GhcRn
-> [SyntaxOpType]
-> SyntaxOpType
-> ([TcSigmaType] -> TcM a)
-> TcM (a, SyntaxExpr GhcTcId)
tcSyntaxOpGen CtOrigin
ListOrigin SyntaxExpr GhcRn
e [ExpSigmaType -> SyntaxOpType
SynType (TcSigmaType -> ExpSigmaType
mkCheckExpType TcSigmaType
tau_pat_ty)]
SyntaxOpType
SynList (([TcSigmaType] -> TcM ([LPat GhcTcId], a, TcSigmaType))
-> TcM (([LPat GhcTcId], a, TcSigmaType), SyntaxExpr GhcTcId))
-> ([TcSigmaType] -> TcM ([LPat GhcTcId], a, TcSigmaType))
-> TcM (([LPat GhcTcId], a, TcSigmaType), SyntaxExpr GhcTcId)
forall a b. (a -> b) -> a -> b
$
\ [elt_ty :: TcSigmaType
elt_ty] ->
do { (pats' :: [LPat GhcTcId]
pats', res :: a
res) <- Checker (LPat GhcRn) (LPat GhcTcId)
-> [LPat GhcRn] -> PatEnv -> TcM a -> TcM ([LPat GhcTcId], a)
forall inp out. Checker inp out -> Checker [inp] [out]
tcMultiple (\p :: LPat GhcRn
p -> LPat GhcRn
-> ExpSigmaType -> PatEnv -> TcM r -> TcM (LPat GhcTcId, r)
forall a.
LPat GhcRn
-> ExpSigmaType -> PatEnv -> TcM a -> TcM (LPat GhcTcId, a)
tc_lpat LPat GhcRn
p (TcSigmaType -> ExpSigmaType
mkCheckExpType TcSigmaType
elt_ty))
[LPat GhcRn]
pats PatEnv
penv TcM a
thing_inside
; ([LPat GhcTcId], a, TcSigmaType)
-> TcM ([LPat GhcTcId], a, TcSigmaType)
forall (m :: * -> *) a. Monad m => a -> m a
return ([LPat GhcTcId]
pats', a
res, TcSigmaType
elt_ty) }
; (LPat GhcTcId, a) -> TcM (LPat GhcTcId, a)
forall (m :: * -> *) a. Monad m => a -> m a
return (XListPat GhcTcId -> [LPat GhcTcId] -> LPat GhcTcId
forall p. XListPat p -> [Pat p] -> Pat p
ListPat (TcSigmaType -> Maybe (TcSigmaType, SyntaxExpr GhcTcId) -> ListPatTc
ListPatTc TcSigmaType
elt_ty ((TcSigmaType, SyntaxExpr GhcTcId)
-> Maybe (TcSigmaType, SyntaxExpr GhcTcId)
forall a. a -> Maybe a
Just (TcSigmaType
tau_pat_ty,SyntaxExpr GhcTcId
e'))) [LPat GhcTcId]
pats', a
res)
}
tc_pat penv :: PatEnv
penv (TuplePat _ pats :: [LPat GhcRn]
pats boxity :: Boxity
boxity) pat_ty :: ExpSigmaType
pat_ty thing_inside :: TcM a
thing_inside
= do { let arity :: Int
arity = [LPat GhcRn] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [LPat GhcRn]
pats
tc :: TyCon
tc = Boxity -> Int -> TyCon
tupleTyCon Boxity
boxity Int
arity
; (coi :: HsWrapper
coi, arg_tys :: [TcSigmaType]
arg_tys) <- (TcSigmaType -> TcM (TcCoercion, [TcSigmaType]))
-> PatEnv -> ExpSigmaType -> TcM (HsWrapper, [TcSigmaType])
forall a.
(TcSigmaType -> TcM (TcCoercion, a))
-> PatEnv -> ExpSigmaType -> TcM (HsWrapper, a)
matchExpectedPatTy (TyCon -> TcSigmaType -> TcM (TcCoercion, [TcSigmaType])
matchExpectedTyConApp TyCon
tc)
PatEnv
penv ExpSigmaType
pat_ty
; let con_arg_tys :: [TcSigmaType]
con_arg_tys = case Boxity
boxity of Unboxed -> Int -> [TcSigmaType] -> [TcSigmaType]
forall a. Int -> [a] -> [a]
drop Int
arity [TcSigmaType]
arg_tys
Boxed -> [TcSigmaType]
arg_tys
; (pats' :: [LPat GhcTcId]
pats', res :: a
res) <- PatEnv
-> [LPat GhcRn]
-> [ExpSigmaType]
-> TcM a
-> TcM ([LPat GhcTcId], a)
forall a.
PatEnv
-> [LPat GhcRn]
-> [ExpSigmaType]
-> TcM a
-> TcM ([LPat GhcTcId], a)
tc_lpats PatEnv
penv [LPat GhcRn]
pats ((TcSigmaType -> ExpSigmaType) -> [TcSigmaType] -> [ExpSigmaType]
forall a b. (a -> b) -> [a] -> [b]
map TcSigmaType -> ExpSigmaType
mkCheckExpType [TcSigmaType]
con_arg_tys)
TcM a
thing_inside
; DynFlags
dflags <- IOEnv (Env TcGblEnv TcLclEnv) DynFlags
forall (m :: * -> *). HasDynFlags m => m DynFlags
getDynFlags
; let
unmangled_result :: LPat GhcTcId
unmangled_result = XTuplePat GhcTcId -> [LPat GhcTcId] -> Boxity -> LPat GhcTcId
forall p. XTuplePat p -> [Pat p] -> Boxity -> Pat p
TuplePat [TcSigmaType]
XTuplePat GhcTcId
con_arg_tys [LPat GhcTcId]
pats' Boxity
boxity
possibly_mangled_result :: LPat GhcTcId
possibly_mangled_result
| GeneralFlag -> DynFlags -> Bool
gopt GeneralFlag
Opt_IrrefutableTuples DynFlags
dflags Bool -> Bool -> Bool
&&
Boxity -> Bool
isBoxed Boxity
boxity = XLazyPat GhcTcId -> LPat GhcTcId -> LPat GhcTcId
forall p. XLazyPat p -> Pat p -> Pat p
LazyPat XLazyPat GhcTcId
NoExt
noExt (SrcSpanLess (LPat GhcTcId) -> LPat GhcTcId
forall a. HasSrcSpan a => SrcSpanLess a -> a
noLoc SrcSpanLess (LPat GhcTcId)
LPat GhcTcId
unmangled_result)
| Bool
otherwise = LPat GhcTcId
unmangled_result
; TcSigmaType
pat_ty <- ExpSigmaType -> TcM TcSigmaType
readExpType ExpSigmaType
pat_ty
; ASSERT( con_arg_tys `equalLength` pats )
(LPat GhcTcId, a) -> TcM (LPat GhcTcId, a)
forall (m :: * -> *) a. Monad m => a -> m a
return (HsWrapper -> LPat GhcTcId -> TcSigmaType -> LPat GhcTcId
forall (id :: Pass).
HsWrapper -> Pat (GhcPass id) -> TcSigmaType -> Pat (GhcPass id)
mkHsWrapPat HsWrapper
coi LPat GhcTcId
possibly_mangled_result TcSigmaType
pat_ty, a
res)
}
tc_pat penv :: PatEnv
penv (SumPat _ pat :: LPat GhcRn
pat alt :: Int
alt arity :: Int
arity ) pat_ty :: ExpSigmaType
pat_ty thing_inside :: TcM a
thing_inside
= do { let tc :: TyCon
tc = Int -> TyCon
sumTyCon Int
arity
; (coi :: HsWrapper
coi, arg_tys :: [TcSigmaType]
arg_tys) <- (TcSigmaType -> TcM (TcCoercion, [TcSigmaType]))
-> PatEnv -> ExpSigmaType -> TcM (HsWrapper, [TcSigmaType])
forall a.
(TcSigmaType -> TcM (TcCoercion, a))
-> PatEnv -> ExpSigmaType -> TcM (HsWrapper, a)
matchExpectedPatTy (TyCon -> TcSigmaType -> TcM (TcCoercion, [TcSigmaType])
matchExpectedTyConApp TyCon
tc)
PatEnv
penv ExpSigmaType
pat_ty
;
let con_arg_tys :: [TcSigmaType]
con_arg_tys = Int -> [TcSigmaType] -> [TcSigmaType]
forall a. Int -> [a] -> [a]
drop Int
arity [TcSigmaType]
arg_tys
; (pat' :: LPat GhcTcId
pat', res :: a
res) <- LPat GhcRn
-> ExpSigmaType -> PatEnv -> TcM a -> TcM (LPat GhcTcId, a)
forall a.
LPat GhcRn
-> ExpSigmaType -> PatEnv -> TcM a -> TcM (LPat GhcTcId, a)
tc_lpat LPat GhcRn
pat (TcSigmaType -> ExpSigmaType
mkCheckExpType ([TcSigmaType]
con_arg_tys [TcSigmaType] -> Int -> TcSigmaType
forall a. Outputable a => [a] -> Int -> a
`getNth` (Int
alt Int -> Int -> Int
forall a. Num a => a -> a -> a
- 1)))
PatEnv
penv TcM a
thing_inside
; TcSigmaType
pat_ty <- ExpSigmaType -> TcM TcSigmaType
readExpType ExpSigmaType
pat_ty
; (LPat GhcTcId, a) -> TcM (LPat GhcTcId, a)
forall (m :: * -> *) a. Monad m => a -> m a
return (HsWrapper -> LPat GhcTcId -> TcSigmaType -> LPat GhcTcId
forall (id :: Pass).
HsWrapper -> Pat (GhcPass id) -> TcSigmaType -> Pat (GhcPass id)
mkHsWrapPat HsWrapper
coi (XSumPat GhcTcId -> LPat GhcTcId -> Int -> Int -> LPat GhcTcId
forall p. XSumPat p -> Pat p -> Int -> Int -> Pat p
SumPat [TcSigmaType]
XSumPat GhcTcId
con_arg_tys LPat GhcTcId
pat' Int
alt Int
arity) TcSigmaType
pat_ty
, a
res)
}
tc_pat penv :: PatEnv
penv (ConPatIn con :: Located (IdP GhcRn)
con arg_pats :: HsConPatDetails GhcRn
arg_pats) pat_ty :: ExpSigmaType
pat_ty thing_inside :: TcM a
thing_inside
= PatEnv
-> Located Name
-> ExpSigmaType
-> HsConPatDetails GhcRn
-> TcM a
-> TcM (LPat GhcTcId, a)
forall a.
PatEnv
-> Located Name
-> ExpSigmaType
-> HsConPatDetails GhcRn
-> TcM a
-> TcM (LPat GhcTcId, a)
tcConPat PatEnv
penv Located Name
Located (IdP GhcRn)
con ExpSigmaType
pat_ty HsConPatDetails GhcRn
arg_pats TcM a
thing_inside
tc_pat penv :: PatEnv
penv (LitPat x :: XLitPat GhcRn
x simple_lit :: HsLit GhcRn
simple_lit) pat_ty :: ExpSigmaType
pat_ty thing_inside :: TcM a
thing_inside
= do { let lit_ty :: TcSigmaType
lit_ty = HsLit GhcRn -> TcSigmaType
forall (p :: Pass). HsLit (GhcPass p) -> TcSigmaType
hsLitType HsLit GhcRn
simple_lit
; HsWrapper
wrap <- PatEnv -> ExpSigmaType -> TcSigmaType -> TcM HsWrapper
tcSubTypePat PatEnv
penv ExpSigmaType
pat_ty TcSigmaType
lit_ty
; a
res <- TcM a
thing_inside
; TcSigmaType
pat_ty <- ExpSigmaType -> TcM TcSigmaType
readExpType ExpSigmaType
pat_ty
; (LPat GhcTcId, a) -> TcM (LPat GhcTcId, a)
forall (m :: * -> *) a. Monad m => a -> m a
return ( HsWrapper -> LPat GhcTcId -> TcSigmaType -> LPat GhcTcId
forall (id :: Pass).
HsWrapper -> Pat (GhcPass id) -> TcSigmaType -> Pat (GhcPass id)
mkHsWrapPat HsWrapper
wrap (XLitPat GhcTcId -> HsLit GhcTcId -> LPat GhcTcId
forall p. XLitPat p -> HsLit p -> Pat p
LitPat XLitPat GhcRn
XLitPat GhcTcId
x (HsLit GhcRn -> HsLit GhcTcId
forall a b. ConvertIdX a b => HsLit a -> HsLit b
convertLit HsLit GhcRn
simple_lit)) TcSigmaType
pat_ty
, a
res) }
tc_pat _ (NPat _ (Located (HsOverLit GhcRn)
-> Located (SrcSpanLess (Located (HsOverLit GhcRn)))
forall a. HasSrcSpan a => a -> Located (SrcSpanLess a)
dL->L l :: SrcSpan
l over_lit :: SrcSpanLess (Located (HsOverLit GhcRn))
over_lit) mb_neg :: Maybe (SyntaxExpr GhcRn)
mb_neg eq :: SyntaxExpr GhcRn
eq) pat_ty :: ExpSigmaType
pat_ty thing_inside :: TcM a
thing_inside
= do { let orig :: CtOrigin
orig = HsOverLit GhcRn -> CtOrigin
LiteralOrigin SrcSpanLess (Located (HsOverLit GhcRn))
HsOverLit GhcRn
over_lit
; ((lit' :: HsOverLit GhcTcId
lit', mb_neg' :: Maybe (SyntaxExpr GhcTcId)
mb_neg'), eq' :: SyntaxExpr GhcTcId
eq')
<- CtOrigin
-> SyntaxExpr GhcRn
-> [SyntaxOpType]
-> ExpSigmaType
-> ([TcSigmaType]
-> TcM (HsOverLit GhcTcId, Maybe (SyntaxExpr GhcTcId)))
-> TcM
((HsOverLit GhcTcId, Maybe (SyntaxExpr GhcTcId)),
SyntaxExpr GhcTcId)
forall a.
CtOrigin
-> SyntaxExpr GhcRn
-> [SyntaxOpType]
-> ExpSigmaType
-> ([TcSigmaType] -> TcM a)
-> TcM (a, SyntaxExpr GhcTcId)
tcSyntaxOp CtOrigin
orig SyntaxExpr GhcRn
eq [ExpSigmaType -> SyntaxOpType
SynType ExpSigmaType
pat_ty, SyntaxOpType
SynAny]
(TcSigmaType -> ExpSigmaType
mkCheckExpType TcSigmaType
boolTy) (([TcSigmaType]
-> TcM (HsOverLit GhcTcId, Maybe (SyntaxExpr GhcTcId)))
-> TcM
((HsOverLit GhcTcId, Maybe (SyntaxExpr GhcTcId)),
SyntaxExpr GhcTcId))
-> ([TcSigmaType]
-> TcM (HsOverLit GhcTcId, Maybe (SyntaxExpr GhcTcId)))
-> TcM
((HsOverLit GhcTcId, Maybe (SyntaxExpr GhcTcId)),
SyntaxExpr GhcTcId)
forall a b. (a -> b) -> a -> b
$
\ [neg_lit_ty :: TcSigmaType
neg_lit_ty] ->
let new_over_lit :: TcSigmaType -> TcM (HsOverLit GhcTcId)
new_over_lit lit_ty :: TcSigmaType
lit_ty = HsOverLit GhcRn -> ExpSigmaType -> TcM (HsOverLit GhcTcId)
newOverloadedLit SrcSpanLess (Located (HsOverLit GhcRn))
HsOverLit GhcRn
over_lit
(TcSigmaType -> ExpSigmaType
mkCheckExpType TcSigmaType
lit_ty)
in case Maybe (SyntaxExpr GhcRn)
mb_neg of
Nothing -> (, Maybe (SyntaxExpr GhcTcId)
forall a. Maybe a
Nothing) (HsOverLit GhcTcId
-> (HsOverLit GhcTcId, Maybe (SyntaxExpr GhcTcId)))
-> TcM (HsOverLit GhcTcId)
-> TcM (HsOverLit GhcTcId, Maybe (SyntaxExpr GhcTcId))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> TcSigmaType -> TcM (HsOverLit GhcTcId)
new_over_lit TcSigmaType
neg_lit_ty
Just neg :: SyntaxExpr GhcRn
neg ->
(SyntaxExpr GhcTcId -> Maybe (SyntaxExpr GhcTcId))
-> (HsOverLit GhcTcId, SyntaxExpr GhcTcId)
-> (HsOverLit GhcTcId, Maybe (SyntaxExpr GhcTcId))
forall (a :: * -> * -> *) b c d.
Arrow a =>
a b c -> a (d, b) (d, c)
second SyntaxExpr GhcTcId -> Maybe (SyntaxExpr GhcTcId)
forall a. a -> Maybe a
Just ((HsOverLit GhcTcId, SyntaxExpr GhcTcId)
-> (HsOverLit GhcTcId, Maybe (SyntaxExpr GhcTcId)))
-> IOEnv
(Env TcGblEnv TcLclEnv) (HsOverLit GhcTcId, SyntaxExpr GhcTcId)
-> TcM (HsOverLit GhcTcId, Maybe (SyntaxExpr GhcTcId))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$>
(CtOrigin
-> SyntaxExpr GhcRn
-> [SyntaxOpType]
-> ExpSigmaType
-> ([TcSigmaType] -> TcM (HsOverLit GhcTcId))
-> IOEnv
(Env TcGblEnv TcLclEnv) (HsOverLit GhcTcId, SyntaxExpr GhcTcId)
forall a.
CtOrigin
-> SyntaxExpr GhcRn
-> [SyntaxOpType]
-> ExpSigmaType
-> ([TcSigmaType] -> TcM a)
-> TcM (a, SyntaxExpr GhcTcId)
tcSyntaxOp CtOrigin
orig SyntaxExpr GhcRn
neg [SyntaxOpType
SynRho] (TcSigmaType -> ExpSigmaType
mkCheckExpType TcSigmaType
neg_lit_ty) (([TcSigmaType] -> TcM (HsOverLit GhcTcId))
-> IOEnv
(Env TcGblEnv TcLclEnv) (HsOverLit GhcTcId, SyntaxExpr GhcTcId))
-> ([TcSigmaType] -> TcM (HsOverLit GhcTcId))
-> IOEnv
(Env TcGblEnv TcLclEnv) (HsOverLit GhcTcId, SyntaxExpr GhcTcId)
forall a b. (a -> b) -> a -> b
$
\ [lit_ty :: TcSigmaType
lit_ty] -> TcSigmaType -> TcM (HsOverLit GhcTcId)
new_over_lit TcSigmaType
lit_ty)
; a
res <- TcM a
thing_inside
; TcSigmaType
pat_ty <- ExpSigmaType -> TcM TcSigmaType
readExpType ExpSigmaType
pat_ty
; (LPat GhcTcId, a) -> TcM (LPat GhcTcId, a)
forall (m :: * -> *) a. Monad m => a -> m a
return (XNPat GhcTcId
-> Located (HsOverLit GhcTcId)
-> Maybe (SyntaxExpr GhcTcId)
-> SyntaxExpr GhcTcId
-> LPat GhcTcId
forall p.
XNPat p
-> Located (HsOverLit p)
-> Maybe (SyntaxExpr p)
-> SyntaxExpr p
-> Pat p
NPat TcSigmaType
XNPat GhcTcId
pat_ty (SrcSpan
-> SrcSpanLess (Located (HsOverLit GhcTcId))
-> Located (HsOverLit GhcTcId)
forall a. HasSrcSpan a => SrcSpan -> SrcSpanLess a -> a
cL SrcSpan
l SrcSpanLess (Located (HsOverLit GhcTcId))
HsOverLit GhcTcId
lit') Maybe (SyntaxExpr GhcTcId)
mb_neg' SyntaxExpr GhcTcId
eq', a
res) }
tc_pat penv :: PatEnv
penv (NPlusKPat _ (Located (IdP GhcRn) -> Located (SrcSpanLess (Located Name))
forall a. HasSrcSpan a => a -> Located (SrcSpanLess a)
dL->L nm_loc :: SrcSpan
nm_loc name :: SrcSpanLess (Located Name)
name)
(Located (HsOverLit GhcRn)
-> Located (SrcSpanLess (Located (HsOverLit GhcRn)))
forall a. HasSrcSpan a => a -> Located (SrcSpanLess a)
dL->L loc :: SrcSpan
loc lit :: SrcSpanLess (Located (HsOverLit GhcRn))
lit) _ ge :: SyntaxExpr GhcRn
ge minus :: SyntaxExpr GhcRn
minus) pat_ty :: ExpSigmaType
pat_ty
thing_inside :: TcM a
thing_inside
= do { TcSigmaType
pat_ty <- ExpSigmaType -> TcM TcSigmaType
expTypeToType ExpSigmaType
pat_ty
; let orig :: CtOrigin
orig = HsOverLit GhcRn -> CtOrigin
LiteralOrigin SrcSpanLess (Located (HsOverLit GhcRn))
HsOverLit GhcRn
lit
; (lit1' :: HsOverLit GhcTcId
lit1', ge' :: SyntaxExpr GhcTcId
ge')
<- CtOrigin
-> SyntaxExpr GhcRn
-> [SyntaxOpType]
-> ExpSigmaType
-> ([TcSigmaType] -> TcM (HsOverLit GhcTcId))
-> IOEnv
(Env TcGblEnv TcLclEnv) (HsOverLit GhcTcId, SyntaxExpr GhcTcId)
forall a.
CtOrigin
-> SyntaxExpr GhcRn
-> [SyntaxOpType]
-> ExpSigmaType
-> ([TcSigmaType] -> TcM a)
-> TcM (a, SyntaxExpr GhcTcId)
tcSyntaxOp CtOrigin
orig SyntaxExpr GhcRn
ge [TcSigmaType -> SyntaxOpType
synKnownType TcSigmaType
pat_ty, SyntaxOpType
SynRho]
(TcSigmaType -> ExpSigmaType
mkCheckExpType TcSigmaType
boolTy) (([TcSigmaType] -> TcM (HsOverLit GhcTcId))
-> IOEnv
(Env TcGblEnv TcLclEnv) (HsOverLit GhcTcId, SyntaxExpr GhcTcId))
-> ([TcSigmaType] -> TcM (HsOverLit GhcTcId))
-> IOEnv
(Env TcGblEnv TcLclEnv) (HsOverLit GhcTcId, SyntaxExpr GhcTcId)
forall a b. (a -> b) -> a -> b
$
\ [lit1_ty :: TcSigmaType
lit1_ty] ->
HsOverLit GhcRn -> ExpSigmaType -> TcM (HsOverLit GhcTcId)
newOverloadedLit SrcSpanLess (Located (HsOverLit GhcRn))
HsOverLit GhcRn
lit (TcSigmaType -> ExpSigmaType
mkCheckExpType TcSigmaType
lit1_ty)
; ((lit2' :: HsOverLit GhcTcId
lit2', minus_wrap :: HsWrapper
minus_wrap, bndr_id :: TcId
bndr_id), minus' :: SyntaxExpr GhcTcId
minus')
<- CtOrigin
-> SyntaxExpr GhcRn
-> [SyntaxOpType]
-> SyntaxOpType
-> ([TcSigmaType] -> TcM (HsOverLit GhcTcId, HsWrapper, TcId))
-> TcM ((HsOverLit GhcTcId, HsWrapper, TcId), SyntaxExpr GhcTcId)
forall a.
CtOrigin
-> SyntaxExpr GhcRn
-> [SyntaxOpType]
-> SyntaxOpType
-> ([TcSigmaType] -> TcM a)
-> TcM (a, SyntaxExpr GhcTcId)
tcSyntaxOpGen CtOrigin
orig SyntaxExpr GhcRn
minus [TcSigmaType -> SyntaxOpType
synKnownType TcSigmaType
pat_ty, SyntaxOpType
SynRho] SyntaxOpType
SynAny (([TcSigmaType] -> TcM (HsOverLit GhcTcId, HsWrapper, TcId))
-> TcM ((HsOverLit GhcTcId, HsWrapper, TcId), SyntaxExpr GhcTcId))
-> ([TcSigmaType] -> TcM (HsOverLit GhcTcId, HsWrapper, TcId))
-> TcM ((HsOverLit GhcTcId, HsWrapper, TcId), SyntaxExpr GhcTcId)
forall a b. (a -> b) -> a -> b
$
\ [lit2_ty :: TcSigmaType
lit2_ty, var_ty :: TcSigmaType
var_ty] ->
do { HsOverLit GhcTcId
lit2' <- HsOverLit GhcRn -> ExpSigmaType -> TcM (HsOverLit GhcTcId)
newOverloadedLit SrcSpanLess (Located (HsOverLit GhcRn))
HsOverLit GhcRn
lit (TcSigmaType -> ExpSigmaType
mkCheckExpType TcSigmaType
lit2_ty)
; (wrap :: HsWrapper
wrap, bndr_id :: TcId
bndr_id) <- SrcSpan -> TcM (HsWrapper, TcId) -> TcM (HsWrapper, TcId)
forall a. SrcSpan -> TcRn a -> TcRn a
setSrcSpan SrcSpan
nm_loc (TcM (HsWrapper, TcId) -> TcM (HsWrapper, TcId))
-> TcM (HsWrapper, TcId) -> TcM (HsWrapper, TcId)
forall a b. (a -> b) -> a -> b
$
PatEnv -> Name -> ExpSigmaType -> TcM (HsWrapper, TcId)
tcPatBndr PatEnv
penv Name
SrcSpanLess (Located Name)
name (TcSigmaType -> ExpSigmaType
mkCheckExpType TcSigmaType
var_ty)
; (HsOverLit GhcTcId, HsWrapper, TcId)
-> TcM (HsOverLit GhcTcId, HsWrapper, TcId)
forall (m :: * -> *) a. Monad m => a -> m a
return (HsOverLit GhcTcId
lit2', HsWrapper
wrap, TcId
bndr_id) }
; IOEnv (Env TcGblEnv TcLclEnv) Bool -> TcRn () -> TcRn ()
forall (m :: * -> *). Monad m => m Bool -> m () -> m ()
unlessM (Extension -> IOEnv (Env TcGblEnv TcLclEnv) Bool
forall gbl lcl. Extension -> TcRnIf gbl lcl Bool
xoptM Extension
LangExt.RebindableSyntax) (TcRn () -> TcRn ()) -> TcRn () -> TcRn ()
forall a b. (a -> b) -> a -> b
$
do { Class
icls <- Name -> TcM Class
tcLookupClass Name
integralClassName
; CtOrigin -> [TcSigmaType] -> TcRn ()
instStupidTheta CtOrigin
orig [Class -> [TcSigmaType] -> TcSigmaType
mkClassPred Class
icls [TcSigmaType
pat_ty]] }
; a
res <- Name -> TcId -> TcM a -> TcM a
forall a. Name -> TcId -> TcM a -> TcM a
tcExtendIdEnv1 Name
SrcSpanLess (Located Name)
name TcId
bndr_id TcM a
thing_inside
; let minus'' :: SyntaxExpr GhcTcId
minus'' = SyntaxExpr GhcTcId
minus' { syn_res_wrap :: HsWrapper
syn_res_wrap =
HsWrapper
minus_wrap HsWrapper -> HsWrapper -> HsWrapper
<.> SyntaxExpr GhcTcId -> HsWrapper
forall p. SyntaxExpr p -> HsWrapper
syn_res_wrap SyntaxExpr GhcTcId
minus' }
pat' :: LPat GhcTcId
pat' = XNPlusKPat GhcTcId
-> Located (IdP GhcTcId)
-> Located (HsOverLit GhcTcId)
-> HsOverLit GhcTcId
-> SyntaxExpr GhcTcId
-> SyntaxExpr GhcTcId
-> LPat GhcTcId
forall p.
XNPlusKPat p
-> Located (IdP p)
-> Located (HsOverLit p)
-> HsOverLit p
-> SyntaxExpr p
-> SyntaxExpr p
-> Pat p
NPlusKPat TcSigmaType
XNPlusKPat GhcTcId
pat_ty (SrcSpan -> SrcSpanLess (Located TcId) -> Located TcId
forall a. HasSrcSpan a => SrcSpan -> SrcSpanLess a -> a
cL SrcSpan
nm_loc SrcSpanLess (Located TcId)
TcId
bndr_id) (SrcSpan
-> SrcSpanLess (Located (HsOverLit GhcTcId))
-> Located (HsOverLit GhcTcId)
forall a. HasSrcSpan a => SrcSpan -> SrcSpanLess a -> a
cL SrcSpan
loc SrcSpanLess (Located (HsOverLit GhcTcId))
HsOverLit GhcTcId
lit1') HsOverLit GhcTcId
lit2'
SyntaxExpr GhcTcId
ge' SyntaxExpr GhcTcId
minus''
; (LPat GhcTcId, a) -> TcM (LPat GhcTcId, a)
forall (m :: * -> *) a. Monad m => a -> m a
return (LPat GhcTcId
pat', a
res) }
tc_pat penv :: PatEnv
penv (SplicePat _ (HsSpliced _ mod_finalizers :: ThModFinalizers
mod_finalizers (HsSplicedPat pat :: LPat GhcRn
pat)))
pat_ty :: ExpSigmaType
pat_ty thing_inside :: TcM a
thing_inside
= do ThModFinalizers -> TcRn ()
addModFinalizersWithLclEnv ThModFinalizers
mod_finalizers
PatEnv
-> LPat GhcRn -> ExpSigmaType -> TcM a -> TcM (LPat GhcTcId, a)
forall a.
PatEnv
-> LPat GhcRn -> ExpSigmaType -> TcM a -> TcM (LPat GhcTcId, a)
tc_pat PatEnv
penv LPat GhcRn
pat ExpSigmaType
pat_ty TcM a
thing_inside
tc_pat _ _other_pat :: LPat GhcRn
_other_pat _ _ = String -> TcM (LPat GhcTcId, a)
forall a. String -> a
panic "tc_pat"
tcConPat :: PatEnv -> Located Name
-> ExpSigmaType
-> HsConPatDetails GhcRn -> TcM a
-> TcM (Pat GhcTcId, a)
tcConPat :: PatEnv
-> Located Name
-> ExpSigmaType
-> HsConPatDetails GhcRn
-> TcM a
-> TcM (LPat GhcTcId, a)
tcConPat penv :: PatEnv
penv con_lname :: Located Name
con_lname@(Located Name -> Located (SrcSpanLess (Located Name))
forall a. HasSrcSpan a => a -> Located (SrcSpanLess a)
dL->L _ con_name :: SrcSpanLess (Located Name)
con_name) pat_ty :: ExpSigmaType
pat_ty arg_pats :: HsConPatDetails GhcRn
arg_pats thing_inside :: TcM a
thing_inside
= do { ConLike
con_like <- Name -> TcM ConLike
tcLookupConLike Name
SrcSpanLess (Located Name)
con_name
; case ConLike
con_like of
RealDataCon data_con :: DataCon
data_con -> PatEnv
-> Located Name
-> DataCon
-> ExpSigmaType
-> HsConPatDetails GhcRn
-> TcM a
-> TcM (LPat GhcTcId, a)
forall a.
PatEnv
-> Located Name
-> DataCon
-> ExpSigmaType
-> HsConPatDetails GhcRn
-> TcM a
-> TcM (LPat GhcTcId, a)
tcDataConPat PatEnv
penv Located Name
con_lname DataCon
data_con
ExpSigmaType
pat_ty HsConPatDetails GhcRn
arg_pats TcM a
thing_inside
PatSynCon pat_syn :: PatSyn
pat_syn -> PatEnv
-> Located Name
-> PatSyn
-> ExpSigmaType
-> HsConPatDetails GhcRn
-> TcM a
-> TcM (LPat GhcTcId, a)
forall a.
PatEnv
-> Located Name
-> PatSyn
-> ExpSigmaType
-> HsConPatDetails GhcRn
-> TcM a
-> TcM (LPat GhcTcId, a)
tcPatSynPat PatEnv
penv Located Name
con_lname PatSyn
pat_syn
ExpSigmaType
pat_ty HsConPatDetails GhcRn
arg_pats TcM a
thing_inside
}
tcDataConPat :: PatEnv -> Located Name -> DataCon
-> ExpSigmaType
-> HsConPatDetails GhcRn -> TcM a
-> TcM (Pat GhcTcId, a)
tcDataConPat :: PatEnv
-> Located Name
-> DataCon
-> ExpSigmaType
-> HsConPatDetails GhcRn
-> TcM a
-> TcM (LPat GhcTcId, a)
tcDataConPat penv :: PatEnv
penv (Located Name -> Located (SrcSpanLess (Located Name))
forall a. HasSrcSpan a => a -> Located (SrcSpanLess a)
dL->L con_span :: SrcSpan
con_span con_name :: SrcSpanLess (Located Name)
con_name) data_con :: DataCon
data_con pat_ty :: ExpSigmaType
pat_ty
arg_pats :: HsConPatDetails GhcRn
arg_pats thing_inside :: TcM a
thing_inside
= do { let tycon :: TyCon
tycon = DataCon -> TyCon
dataConTyCon DataCon
data_con
(univ_tvs :: [TcId]
univ_tvs, ex_tvs :: [TcId]
ex_tvs, eq_spec :: [EqSpec]
eq_spec, theta :: [TcSigmaType]
theta, arg_tys :: [TcSigmaType]
arg_tys, _)
= DataCon
-> ([TcId], [TcId], [EqSpec], [TcSigmaType], [TcSigmaType],
TcSigmaType)
dataConFullSig DataCon
data_con
header :: Located ConLike
header = SrcSpan -> SrcSpanLess (Located ConLike) -> Located ConLike
forall a. HasSrcSpan a => SrcSpan -> SrcSpanLess a -> a
cL SrcSpan
con_span (DataCon -> ConLike
RealDataCon DataCon
data_con)
; (wrap :: HsWrapper
wrap, ctxt_res_tys :: [TcSigmaType]
ctxt_res_tys) <- PatEnv -> TyCon -> ExpSigmaType -> TcM (HsWrapper, [TcSigmaType])
matchExpectedConTy PatEnv
penv TyCon
tycon ExpSigmaType
pat_ty
; TcSigmaType
pat_ty <- ExpSigmaType -> TcM TcSigmaType
readExpType ExpSigmaType
pat_ty
; SrcSpan -> TcRn () -> TcRn ()
forall a. SrcSpan -> TcRn a -> TcRn a
setSrcSpan SrcSpan
con_span (TcRn () -> TcRn ()) -> TcRn () -> TcRn ()
forall a b. (a -> b) -> a -> b
$ DataCon -> [TcSigmaType] -> TcRn ()
addDataConStupidTheta DataCon
data_con [TcSigmaType]
ctxt_res_tys
; let all_arg_tys :: [TcSigmaType]
all_arg_tys = [EqSpec] -> [TcSigmaType]
eqSpecPreds [EqSpec]
eq_spec [TcSigmaType] -> [TcSigmaType] -> [TcSigmaType]
forall a. [a] -> [a] -> [a]
++ [TcSigmaType]
theta [TcSigmaType] -> [TcSigmaType] -> [TcSigmaType]
forall a. [a] -> [a] -> [a]
++ [TcSigmaType]
arg_tys
; [TcId] -> [TcSigmaType] -> PatEnv -> TcRn ()
checkExistentials [TcId]
ex_tvs [TcSigmaType]
all_arg_tys PatEnv
penv
; TCvSubst
tenv <- CtOrigin -> [TcId] -> [TcSigmaType] -> TcM TCvSubst
instTyVarsWith CtOrigin
PatOrigin [TcId]
univ_tvs [TcSigmaType]
ctxt_res_tys
; (tenv :: TCvSubst
tenv, ex_tvs' :: [TcId]
ex_tvs') <- TCvSubst -> [TcId] -> TcM (TCvSubst, [TcId])
tcInstSuperSkolTyVarsX TCvSubst
tenv [TcId]
ex_tvs
; let
arg_tys' :: [TcSigmaType]
arg_tys' = HasCallStack => TCvSubst -> [TcSigmaType] -> [TcSigmaType]
TCvSubst -> [TcSigmaType] -> [TcSigmaType]
substTys TCvSubst
tenv [TcSigmaType]
arg_tys
; String -> SDoc -> TcRn ()
traceTc "tcConPat" ([SDoc] -> SDoc
vcat [ Name -> SDoc
forall a. Outputable a => a -> SDoc
ppr Name
SrcSpanLess (Located Name)
con_name
, [TcId] -> SDoc
pprTyVars [TcId]
univ_tvs
, [TcId] -> SDoc
pprTyVars [TcId]
ex_tvs
, [EqSpec] -> SDoc
forall a. Outputable a => a -> SDoc
ppr [EqSpec]
eq_spec
, [TcSigmaType] -> SDoc
forall a. Outputable a => a -> SDoc
ppr [TcSigmaType]
theta
, [TcId] -> SDoc
pprTyVars [TcId]
ex_tvs'
, [TcSigmaType] -> SDoc
forall a. Outputable a => a -> SDoc
ppr [TcSigmaType]
ctxt_res_tys
, [TcSigmaType] -> SDoc
forall a. Outputable a => a -> SDoc
ppr [TcSigmaType]
arg_tys'
, HsConPatDetails GhcRn -> SDoc
forall a. Outputable a => a -> SDoc
ppr HsConPatDetails GhcRn
arg_pats ])
; if [TcId] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [TcId]
ex_tvs Bool -> Bool -> Bool
&& [EqSpec] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [EqSpec]
eq_spec Bool -> Bool -> Bool
&& [TcSigmaType] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [TcSigmaType]
theta
then do {
(arg_pats' :: HsConPatDetails GhcTcId
arg_pats', res :: a
res) <- ConLike
-> [TcSigmaType]
-> HsConPatDetails GhcRn
-> PatEnv
-> TcM a
-> TcM (HsConPatDetails GhcTcId, a)
ConLike
-> [TcSigmaType]
-> Checker (HsConPatDetails GhcRn) (HsConPatDetails GhcTcId)
tcConArgs (DataCon -> ConLike
RealDataCon DataCon
data_con) [TcSigmaType]
arg_tys'
HsConPatDetails GhcRn
arg_pats PatEnv
penv TcM a
thing_inside
; let res_pat :: LPat GhcTcId
res_pat = ConPatOut :: forall p.
Located ConLike
-> [TcSigmaType]
-> [TcId]
-> [TcId]
-> TcEvBinds
-> HsConPatDetails p
-> HsWrapper
-> Pat p
ConPatOut { pat_con :: Located ConLike
pat_con = Located ConLike
header,
pat_tvs :: [TcId]
pat_tvs = [], pat_dicts :: [TcId]
pat_dicts = [],
pat_binds :: TcEvBinds
pat_binds = TcEvBinds
emptyTcEvBinds,
pat_args :: HsConPatDetails GhcTcId
pat_args = HsConPatDetails GhcTcId
arg_pats',
pat_arg_tys :: [TcSigmaType]
pat_arg_tys = [TcSigmaType]
ctxt_res_tys,
pat_wrap :: HsWrapper
pat_wrap = HsWrapper
idHsWrapper }
; (LPat GhcTcId, a) -> TcM (LPat GhcTcId, a)
forall (m :: * -> *) a. Monad m => a -> m a
return (HsWrapper -> LPat GhcTcId -> TcSigmaType -> LPat GhcTcId
forall (id :: Pass).
HsWrapper -> Pat (GhcPass id) -> TcSigmaType -> Pat (GhcPass id)
mkHsWrapPat HsWrapper
wrap LPat GhcTcId
res_pat TcSigmaType
pat_ty, a
res) }
else do
{ let theta' :: [TcSigmaType]
theta' = HasCallStack => TCvSubst -> [TcSigmaType] -> [TcSigmaType]
TCvSubst -> [TcSigmaType] -> [TcSigmaType]
substTheta TCvSubst
tenv ([EqSpec] -> [TcSigmaType]
eqSpecPreds [EqSpec]
eq_spec [TcSigmaType] -> [TcSigmaType] -> [TcSigmaType]
forall a. [a] -> [a] -> [a]
++ [TcSigmaType]
theta)
no_equalities :: Bool
no_equalities = Bool -> Bool
not ((TcSigmaType -> Bool) -> [TcSigmaType] -> Bool
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
any TcSigmaType -> Bool
isNomEqPred [TcSigmaType]
theta')
skol_info :: SkolemInfo
skol_info = ConLike -> HsMatchContext Name -> SkolemInfo
PatSkol (DataCon -> ConLike
RealDataCon DataCon
data_con) HsMatchContext Name
mc
mc :: HsMatchContext Name
mc = case PatEnv -> PatCtxt
pe_ctxt PatEnv
penv of
LamPat mc :: HsMatchContext Name
mc -> HsMatchContext Name
mc
LetPat {} -> HsMatchContext Name
forall id. HsMatchContext id
PatBindRhs
; Bool
gadts_on <- Extension -> IOEnv (Env TcGblEnv TcLclEnv) Bool
forall gbl lcl. Extension -> TcRnIf gbl lcl Bool
xoptM Extension
LangExt.GADTs
; Bool
families_on <- Extension -> IOEnv (Env TcGblEnv TcLclEnv) Bool
forall gbl lcl. Extension -> TcRnIf gbl lcl Bool
xoptM Extension
LangExt.TypeFamilies
; Bool -> SDoc -> TcRn ()
checkTc (Bool
no_equalities Bool -> Bool -> Bool
|| Bool
gadts_on Bool -> Bool -> Bool
|| Bool
families_on)
(String -> SDoc
text "A pattern match on a GADT requires the" SDoc -> SDoc -> SDoc
<+>
String -> SDoc
text "GADTs or TypeFamilies language extension")
; [TcId]
given <- [TcSigmaType] -> TcM [TcId]
newEvVars [TcSigmaType]
theta'
; (ev_binds :: TcEvBinds
ev_binds, (arg_pats' :: HsConPatDetails GhcTcId
arg_pats', res :: a
res))
<- SkolemInfo
-> [TcId]
-> [TcId]
-> TcM (HsConPatDetails GhcTcId, a)
-> TcM (TcEvBinds, (HsConPatDetails GhcTcId, a))
forall result.
SkolemInfo
-> [TcId] -> [TcId] -> TcM result -> TcM (TcEvBinds, result)
checkConstraints SkolemInfo
skol_info [TcId]
ex_tvs' [TcId]
given (TcM (HsConPatDetails GhcTcId, a)
-> TcM (TcEvBinds, (HsConPatDetails GhcTcId, a)))
-> TcM (HsConPatDetails GhcTcId, a)
-> TcM (TcEvBinds, (HsConPatDetails GhcTcId, a))
forall a b. (a -> b) -> a -> b
$
ConLike
-> [TcSigmaType]
-> HsConPatDetails GhcRn
-> PatEnv
-> TcM a
-> TcM (HsConPatDetails GhcTcId, a)
ConLike
-> [TcSigmaType]
-> Checker (HsConPatDetails GhcRn) (HsConPatDetails GhcTcId)
tcConArgs (DataCon -> ConLike
RealDataCon DataCon
data_con) [TcSigmaType]
arg_tys' HsConPatDetails GhcRn
arg_pats PatEnv
penv TcM a
thing_inside
; let res_pat :: LPat GhcTcId
res_pat = ConPatOut :: forall p.
Located ConLike
-> [TcSigmaType]
-> [TcId]
-> [TcId]
-> TcEvBinds
-> HsConPatDetails p
-> HsWrapper
-> Pat p
ConPatOut { pat_con :: Located ConLike
pat_con = Located ConLike
header,
pat_tvs :: [TcId]
pat_tvs = [TcId]
ex_tvs',
pat_dicts :: [TcId]
pat_dicts = [TcId]
given,
pat_binds :: TcEvBinds
pat_binds = TcEvBinds
ev_binds,
pat_args :: HsConPatDetails GhcTcId
pat_args = HsConPatDetails GhcTcId
arg_pats',
pat_arg_tys :: [TcSigmaType]
pat_arg_tys = [TcSigmaType]
ctxt_res_tys,
pat_wrap :: HsWrapper
pat_wrap = HsWrapper
idHsWrapper }
; (LPat GhcTcId, a) -> TcM (LPat GhcTcId, a)
forall (m :: * -> *) a. Monad m => a -> m a
return (HsWrapper -> LPat GhcTcId -> TcSigmaType -> LPat GhcTcId
forall (id :: Pass).
HsWrapper -> Pat (GhcPass id) -> TcSigmaType -> Pat (GhcPass id)
mkHsWrapPat HsWrapper
wrap LPat GhcTcId
res_pat TcSigmaType
pat_ty, a
res)
} }
tcPatSynPat :: PatEnv -> Located Name -> PatSyn
-> ExpSigmaType
-> HsConPatDetails GhcRn -> TcM a
-> TcM (Pat GhcTcId, a)
tcPatSynPat :: PatEnv
-> Located Name
-> PatSyn
-> ExpSigmaType
-> HsConPatDetails GhcRn
-> TcM a
-> TcM (LPat GhcTcId, a)
tcPatSynPat penv :: PatEnv
penv (Located Name -> Located (SrcSpanLess (Located Name))
forall a. HasSrcSpan a => a -> Located (SrcSpanLess a)
dL->L con_span :: SrcSpan
con_span _) pat_syn :: PatSyn
pat_syn pat_ty :: ExpSigmaType
pat_ty arg_pats :: HsConPatDetails GhcRn
arg_pats thing_inside :: TcM a
thing_inside
= do { let (univ_tvs :: [TcId]
univ_tvs, req_theta :: [TcSigmaType]
req_theta, ex_tvs :: [TcId]
ex_tvs, prov_theta :: [TcSigmaType]
prov_theta, arg_tys :: [TcSigmaType]
arg_tys, ty :: TcSigmaType
ty) = PatSyn
-> ([TcId], [TcSigmaType], [TcId], [TcSigmaType], [TcSigmaType],
TcSigmaType)
patSynSig PatSyn
pat_syn
; (subst :: TCvSubst
subst, univ_tvs' :: [TcId]
univ_tvs') <- [TcId] -> TcM (TCvSubst, [TcId])
newMetaTyVars [TcId]
univ_tvs
; let all_arg_tys :: [TcSigmaType]
all_arg_tys = TcSigmaType
ty TcSigmaType -> [TcSigmaType] -> [TcSigmaType]
forall a. a -> [a] -> [a]
: [TcSigmaType]
prov_theta [TcSigmaType] -> [TcSigmaType] -> [TcSigmaType]
forall a. [a] -> [a] -> [a]
++ [TcSigmaType]
arg_tys
; [TcId] -> [TcSigmaType] -> PatEnv -> TcRn ()
checkExistentials [TcId]
ex_tvs [TcSigmaType]
all_arg_tys PatEnv
penv
; (tenv :: TCvSubst
tenv, ex_tvs' :: [TcId]
ex_tvs') <- TCvSubst -> [TcId] -> TcM (TCvSubst, [TcId])
tcInstSuperSkolTyVarsX TCvSubst
subst [TcId]
ex_tvs
; let ty' :: TcSigmaType
ty' = HasCallStack => TCvSubst -> TcSigmaType -> TcSigmaType
TCvSubst -> TcSigmaType -> TcSigmaType
substTy TCvSubst
tenv TcSigmaType
ty
arg_tys' :: [TcSigmaType]
arg_tys' = HasCallStack => TCvSubst -> [TcSigmaType] -> [TcSigmaType]
TCvSubst -> [TcSigmaType] -> [TcSigmaType]
substTys TCvSubst
tenv [TcSigmaType]
arg_tys
prov_theta' :: [TcSigmaType]
prov_theta' = HasCallStack => TCvSubst -> [TcSigmaType] -> [TcSigmaType]
TCvSubst -> [TcSigmaType] -> [TcSigmaType]
substTheta TCvSubst
tenv [TcSigmaType]
prov_theta
req_theta' :: [TcSigmaType]
req_theta' = HasCallStack => TCvSubst -> [TcSigmaType] -> [TcSigmaType]
TCvSubst -> [TcSigmaType] -> [TcSigmaType]
substTheta TCvSubst
tenv [TcSigmaType]
req_theta
; HsWrapper
wrap <- PatEnv -> ExpSigmaType -> TcSigmaType -> TcM HsWrapper
tcSubTypePat PatEnv
penv ExpSigmaType
pat_ty TcSigmaType
ty'
; String -> SDoc -> TcRn ()
traceTc "tcPatSynPat" (PatSyn -> SDoc
forall a. Outputable a => a -> SDoc
ppr PatSyn
pat_syn SDoc -> SDoc -> SDoc
$$
ExpSigmaType -> SDoc
forall a. Outputable a => a -> SDoc
ppr ExpSigmaType
pat_ty SDoc -> SDoc -> SDoc
$$
TcSigmaType -> SDoc
forall a. Outputable a => a -> SDoc
ppr TcSigmaType
ty' SDoc -> SDoc -> SDoc
$$
[TcId] -> SDoc
forall a. Outputable a => a -> SDoc
ppr [TcId]
ex_tvs' SDoc -> SDoc -> SDoc
$$
[TcSigmaType] -> SDoc
forall a. Outputable a => a -> SDoc
ppr [TcSigmaType]
prov_theta' SDoc -> SDoc -> SDoc
$$
[TcSigmaType] -> SDoc
forall a. Outputable a => a -> SDoc
ppr [TcSigmaType]
req_theta' SDoc -> SDoc -> SDoc
$$
[TcSigmaType] -> SDoc
forall a. Outputable a => a -> SDoc
ppr [TcSigmaType]
arg_tys')
; [TcId]
prov_dicts' <- [TcSigmaType] -> TcM [TcId]
newEvVars [TcSigmaType]
prov_theta'
; let skol_info :: SkolemInfo
skol_info = case PatEnv -> PatCtxt
pe_ctxt PatEnv
penv of
LamPat mc :: HsMatchContext Name
mc -> ConLike -> HsMatchContext Name -> SkolemInfo
PatSkol (PatSyn -> ConLike
PatSynCon PatSyn
pat_syn) HsMatchContext Name
mc
LetPat {} -> SkolemInfo
UnkSkol
; HsWrapper
req_wrap <- CtOrigin -> [TcSigmaType] -> [TcSigmaType] -> TcM HsWrapper
instCall CtOrigin
PatOrigin ([TcId] -> [TcSigmaType]
mkTyVarTys [TcId]
univ_tvs') [TcSigmaType]
req_theta'
; String -> SDoc -> TcRn ()
traceTc "instCall" (HsWrapper -> SDoc
forall a. Outputable a => a -> SDoc
ppr HsWrapper
req_wrap)
; String -> SDoc -> TcRn ()
traceTc "checkConstraints {" SDoc
Outputable.empty
; (ev_binds :: TcEvBinds
ev_binds, (arg_pats' :: HsConPatDetails GhcTcId
arg_pats', res :: a
res))
<- SkolemInfo
-> [TcId]
-> [TcId]
-> TcM (HsConPatDetails GhcTcId, a)
-> TcM (TcEvBinds, (HsConPatDetails GhcTcId, a))
forall result.
SkolemInfo
-> [TcId] -> [TcId] -> TcM result -> TcM (TcEvBinds, result)
checkConstraints SkolemInfo
skol_info [TcId]
ex_tvs' [TcId]
prov_dicts' (TcM (HsConPatDetails GhcTcId, a)
-> TcM (TcEvBinds, (HsConPatDetails GhcTcId, a)))
-> TcM (HsConPatDetails GhcTcId, a)
-> TcM (TcEvBinds, (HsConPatDetails GhcTcId, a))
forall a b. (a -> b) -> a -> b
$
ConLike
-> [TcSigmaType]
-> HsConPatDetails GhcRn
-> PatEnv
-> TcM a
-> TcM (HsConPatDetails GhcTcId, a)
ConLike
-> [TcSigmaType]
-> Checker (HsConPatDetails GhcRn) (HsConPatDetails GhcTcId)
tcConArgs (PatSyn -> ConLike
PatSynCon PatSyn
pat_syn) [TcSigmaType]
arg_tys' HsConPatDetails GhcRn
arg_pats PatEnv
penv TcM a
thing_inside
; String -> SDoc -> TcRn ()
traceTc "checkConstraints }" (TcEvBinds -> SDoc
forall a. Outputable a => a -> SDoc
ppr TcEvBinds
ev_binds)
; let res_pat :: LPat GhcTcId
res_pat = ConPatOut :: forall p.
Located ConLike
-> [TcSigmaType]
-> [TcId]
-> [TcId]
-> TcEvBinds
-> HsConPatDetails p
-> HsWrapper
-> Pat p
ConPatOut { pat_con :: Located ConLike
pat_con = SrcSpan -> SrcSpanLess (Located ConLike) -> Located ConLike
forall a. HasSrcSpan a => SrcSpan -> SrcSpanLess a -> a
cL SrcSpan
con_span (SrcSpanLess (Located ConLike) -> Located ConLike)
-> SrcSpanLess (Located ConLike) -> Located ConLike
forall a b. (a -> b) -> a -> b
$ PatSyn -> ConLike
PatSynCon PatSyn
pat_syn,
pat_tvs :: [TcId]
pat_tvs = [TcId]
ex_tvs',
pat_dicts :: [TcId]
pat_dicts = [TcId]
prov_dicts',
pat_binds :: TcEvBinds
pat_binds = TcEvBinds
ev_binds,
pat_args :: HsConPatDetails GhcTcId
pat_args = HsConPatDetails GhcTcId
arg_pats',
pat_arg_tys :: [TcSigmaType]
pat_arg_tys = [TcId] -> [TcSigmaType]
mkTyVarTys [TcId]
univ_tvs',
pat_wrap :: HsWrapper
pat_wrap = HsWrapper
req_wrap }
; TcSigmaType
pat_ty <- ExpSigmaType -> TcM TcSigmaType
readExpType ExpSigmaType
pat_ty
; (LPat GhcTcId, a) -> TcM (LPat GhcTcId, a)
forall (m :: * -> *) a. Monad m => a -> m a
return (HsWrapper -> LPat GhcTcId -> TcSigmaType -> LPat GhcTcId
forall (id :: Pass).
HsWrapper -> Pat (GhcPass id) -> TcSigmaType -> Pat (GhcPass id)
mkHsWrapPat HsWrapper
wrap LPat GhcTcId
res_pat TcSigmaType
pat_ty, a
res) }
matchExpectedPatTy :: (TcRhoType -> TcM (TcCoercionN, a))
-> PatEnv -> ExpSigmaType -> TcM (HsWrapper, a)
matchExpectedPatTy :: (TcSigmaType -> TcM (TcCoercion, a))
-> PatEnv -> ExpSigmaType -> TcM (HsWrapper, a)
matchExpectedPatTy inner_match :: TcSigmaType -> TcM (TcCoercion, a)
inner_match (PE { pe_orig :: PatEnv -> CtOrigin
pe_orig = CtOrigin
orig }) pat_ty :: ExpSigmaType
pat_ty
= do { TcSigmaType
pat_ty <- ExpSigmaType -> TcM TcSigmaType
expTypeToType ExpSigmaType
pat_ty
; (wrap :: HsWrapper
wrap, pat_rho :: TcSigmaType
pat_rho) <- CtOrigin -> TcSigmaType -> TcM (HsWrapper, TcSigmaType)
topInstantiate CtOrigin
orig TcSigmaType
pat_ty
; (co :: TcCoercion
co, res :: a
res) <- TcSigmaType -> TcM (TcCoercion, a)
inner_match TcSigmaType
pat_rho
; String -> SDoc -> TcRn ()
traceTc "matchExpectedPatTy" (TcSigmaType -> SDoc
forall a. Outputable a => a -> SDoc
ppr TcSigmaType
pat_ty SDoc -> SDoc -> SDoc
$$ HsWrapper -> SDoc
forall a. Outputable a => a -> SDoc
ppr HsWrapper
wrap)
; (HsWrapper, a) -> TcM (HsWrapper, a)
forall (m :: * -> *) a. Monad m => a -> m a
return (TcCoercion -> HsWrapper
mkWpCastN (TcCoercion -> TcCoercion
mkTcSymCo TcCoercion
co) HsWrapper -> HsWrapper -> HsWrapper
<.> HsWrapper
wrap, a
res) }
matchExpectedConTy :: PatEnv
-> TyCon
-> ExpSigmaType
-> TcM (HsWrapper, [TcSigmaType])
matchExpectedConTy :: PatEnv -> TyCon -> ExpSigmaType -> TcM (HsWrapper, [TcSigmaType])
matchExpectedConTy (PE { pe_orig :: PatEnv -> CtOrigin
pe_orig = CtOrigin
orig }) data_tc :: TyCon
data_tc exp_pat_ty :: ExpSigmaType
exp_pat_ty
| Just (fam_tc :: TyCon
fam_tc, fam_args :: [TcSigmaType]
fam_args, co_tc :: CoAxiom Unbranched
co_tc) <- TyCon -> Maybe (TyCon, [TcSigmaType], CoAxiom Unbranched)
tyConFamInstSig_maybe TyCon
data_tc
= do { TcSigmaType
pat_ty <- ExpSigmaType -> TcM TcSigmaType
expTypeToType ExpSigmaType
exp_pat_ty
; (wrap :: HsWrapper
wrap, pat_rho :: TcSigmaType
pat_rho) <- CtOrigin -> TcSigmaType -> TcM (HsWrapper, TcSigmaType)
topInstantiate CtOrigin
orig TcSigmaType
pat_ty
; (subst :: TCvSubst
subst, tvs' :: [TcId]
tvs') <- [TcId] -> TcM (TCvSubst, [TcId])
newMetaTyVars (TyCon -> [TcId]
tyConTyVars TyCon
data_tc)
; String -> SDoc -> TcRn ()
traceTc "matchExpectedConTy" ([SDoc] -> SDoc
vcat [TyCon -> SDoc
forall a. Outputable a => a -> SDoc
ppr TyCon
data_tc,
[TcId] -> SDoc
forall a. Outputable a => a -> SDoc
ppr (TyCon -> [TcId]
tyConTyVars TyCon
data_tc),
TyCon -> SDoc
forall a. Outputable a => a -> SDoc
ppr TyCon
fam_tc, [TcSigmaType] -> SDoc
forall a. Outputable a => a -> SDoc
ppr [TcSigmaType]
fam_args,
ExpSigmaType -> SDoc
forall a. Outputable a => a -> SDoc
ppr ExpSigmaType
exp_pat_ty,
TcSigmaType -> SDoc
forall a. Outputable a => a -> SDoc
ppr TcSigmaType
pat_ty,
TcSigmaType -> SDoc
forall a. Outputable a => a -> SDoc
ppr TcSigmaType
pat_rho, HsWrapper -> SDoc
forall a. Outputable a => a -> SDoc
ppr HsWrapper
wrap])
; TcCoercion
co1 <- Maybe (HsExpr GhcRn)
-> TcSigmaType -> TcSigmaType -> TcM TcCoercion
unifyType Maybe (HsExpr GhcRn)
forall a. Maybe a
Nothing (TyCon -> [TcSigmaType] -> TcSigmaType
mkTyConApp TyCon
fam_tc (HasCallStack => TCvSubst -> [TcSigmaType] -> [TcSigmaType]
TCvSubst -> [TcSigmaType] -> [TcSigmaType]
substTys TCvSubst
subst [TcSigmaType]
fam_args)) TcSigmaType
pat_rho
; let tys' :: [TcSigmaType]
tys' = [TcId] -> [TcSigmaType]
mkTyVarTys [TcId]
tvs'
co2 :: TcCoercion
co2 = CoAxiom Unbranched -> [TcSigmaType] -> [TcCoercion] -> TcCoercion
mkTcUnbranchedAxInstCo CoAxiom Unbranched
co_tc [TcSigmaType]
tys' []
full_co :: TcCoercion
full_co = TcCoercion -> TcCoercion
mkTcSubCo (TcCoercion -> TcCoercion
mkTcSymCo TcCoercion
co1) TcCoercion -> TcCoercion -> TcCoercion
`mkTcTransCo` TcCoercion
co2
; (HsWrapper, [TcSigmaType]) -> TcM (HsWrapper, [TcSigmaType])
forall (m :: * -> *) a. Monad m => a -> m a
return ( TcCoercion -> HsWrapper
mkWpCastR TcCoercion
full_co HsWrapper -> HsWrapper -> HsWrapper
<.> HsWrapper
wrap, [TcSigmaType]
tys') }
| Bool
otherwise
= do { TcSigmaType
pat_ty <- ExpSigmaType -> TcM TcSigmaType
expTypeToType ExpSigmaType
exp_pat_ty
; (wrap :: HsWrapper
wrap, pat_rho :: TcSigmaType
pat_rho) <- CtOrigin -> TcSigmaType -> TcM (HsWrapper, TcSigmaType)
topInstantiate CtOrigin
orig TcSigmaType
pat_ty
; (coi :: TcCoercion
coi, tys :: [TcSigmaType]
tys) <- TyCon -> TcSigmaType -> TcM (TcCoercion, [TcSigmaType])
matchExpectedTyConApp TyCon
data_tc TcSigmaType
pat_rho
; (HsWrapper, [TcSigmaType]) -> TcM (HsWrapper, [TcSigmaType])
forall (m :: * -> *) a. Monad m => a -> m a
return (TcCoercion -> HsWrapper
mkWpCastN (TcCoercion -> TcCoercion
mkTcSymCo TcCoercion
coi) HsWrapper -> HsWrapper -> HsWrapper
<.> HsWrapper
wrap, [TcSigmaType]
tys) }
tcConArgs :: ConLike -> [TcSigmaType]
-> Checker (HsConPatDetails GhcRn) (HsConPatDetails GhcTc)
tcConArgs :: ConLike
-> [TcSigmaType]
-> Checker (HsConPatDetails GhcRn) (HsConPatDetails GhcTcId)
tcConArgs con_like :: ConLike
con_like arg_tys :: [TcSigmaType]
arg_tys (PrefixCon arg_pats :: [LPat GhcRn]
arg_pats) penv :: PatEnv
penv thing_inside :: TcM r
thing_inside
= do { Bool -> SDoc -> TcRn ()
checkTc (Int
con_arity Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
no_of_args)
(SDoc -> ConLike -> Int -> Int -> SDoc
forall a. Outputable a => SDoc -> a -> Int -> Int -> SDoc
arityErr (String -> SDoc
text "constructor") ConLike
con_like Int
con_arity Int
no_of_args)
; let pats_w_tys :: [(LPat GhcRn, TcSigmaType)]
pats_w_tys = String
-> [LPat GhcRn] -> [TcSigmaType] -> [(LPat GhcRn, TcSigmaType)]
forall a b. String -> [a] -> [b] -> [(a, b)]
zipEqual "tcConArgs" [LPat GhcRn]
arg_pats [TcSigmaType]
arg_tys
; (arg_pats' :: [LPat GhcTcId]
arg_pats', res :: r
res) <- Checker (LPat GhcRn, TcSigmaType) (LPat GhcTcId)
-> [(LPat GhcRn, TcSigmaType)]
-> PatEnv
-> TcM r
-> TcM ([LPat GhcTcId], r)
forall inp out. Checker inp out -> Checker [inp] [out]
tcMultiple Checker (LPat GhcRn, TcSigmaType) (LPat GhcTcId)
tcConArg [(LPat GhcRn, TcSigmaType)]
pats_w_tys
PatEnv
penv TcM r
thing_inside
; (HsConPatDetails GhcTcId, r)
-> IOEnv (Env TcGblEnv TcLclEnv) (HsConPatDetails GhcTcId, r)
forall (m :: * -> *) a. Monad m => a -> m a
return ([LPat GhcTcId] -> HsConPatDetails GhcTcId
forall arg rec. [arg] -> HsConDetails arg rec
PrefixCon [LPat GhcTcId]
arg_pats', r
res) }
where
con_arity :: Int
con_arity = ConLike -> Int
conLikeArity ConLike
con_like
no_of_args :: Int
no_of_args = [LPat GhcRn] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [LPat GhcRn]
arg_pats
tcConArgs con_like :: ConLike
con_like arg_tys :: [TcSigmaType]
arg_tys (InfixCon p1 :: LPat GhcRn
p1 p2 :: LPat GhcRn
p2) penv :: PatEnv
penv thing_inside :: TcM r
thing_inside
= do { Bool -> SDoc -> TcRn ()
checkTc (Int
con_arity Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== 2)
(SDoc -> ConLike -> Int -> Int -> SDoc
forall a. Outputable a => SDoc -> a -> Int -> Int -> SDoc
arityErr (String -> SDoc
text "constructor") ConLike
con_like Int
con_arity 2)
; let [arg_ty1 :: TcSigmaType
arg_ty1,arg_ty2 :: TcSigmaType
arg_ty2] = [TcSigmaType]
arg_tys
; ([p1' :: LPat GhcTcId
p1',p2' :: LPat GhcTcId
p2'], res :: r
res) <- Checker (LPat GhcRn, TcSigmaType) (LPat GhcTcId)
-> [(LPat GhcRn, TcSigmaType)]
-> PatEnv
-> TcM r
-> TcM ([LPat GhcTcId], r)
forall inp out. Checker inp out -> Checker [inp] [out]
tcMultiple Checker (LPat GhcRn, TcSigmaType) (LPat GhcTcId)
tcConArg [(LPat GhcRn
p1,TcSigmaType
arg_ty1),(LPat GhcRn
p2,TcSigmaType
arg_ty2)]
PatEnv
penv TcM r
thing_inside
; (HsConPatDetails GhcTcId, r)
-> IOEnv (Env TcGblEnv TcLclEnv) (HsConPatDetails GhcTcId, r)
forall (m :: * -> *) a. Monad m => a -> m a
return (LPat GhcTcId -> LPat GhcTcId -> HsConPatDetails GhcTcId
forall arg rec. arg -> arg -> HsConDetails arg rec
InfixCon LPat GhcTcId
p1' LPat GhcTcId
p2', r
res) }
where
con_arity :: Int
con_arity = ConLike -> Int
conLikeArity ConLike
con_like
tcConArgs con_like :: ConLike
con_like arg_tys :: [TcSigmaType]
arg_tys (RecCon (HsRecFields rpats :: [LHsRecField GhcRn (LPat GhcRn)]
rpats dd :: Maybe Int
dd)) penv :: PatEnv
penv thing_inside :: TcM r
thing_inside
= do { (rpats' :: [LHsRecField GhcTcId (LPat GhcTcId)]
rpats', res :: r
res) <- Checker
(LHsRecField GhcRn (LPat GhcRn))
(LHsRecField GhcTcId (LPat GhcTcId))
-> [LHsRecField GhcRn (LPat GhcRn)]
-> PatEnv
-> TcM r
-> TcM ([LHsRecField GhcTcId (LPat GhcTcId)], r)
forall inp out. Checker inp out -> Checker [inp] [out]
tcMultiple Checker
(LHsRecField GhcRn (LPat GhcRn))
(LHsRecField GhcTcId (LPat GhcTcId))
tc_field [LHsRecField GhcRn (LPat GhcRn)]
rpats PatEnv
penv TcM r
thing_inside
; (HsConPatDetails GhcTcId, r)
-> IOEnv (Env TcGblEnv TcLclEnv) (HsConPatDetails GhcTcId, r)
forall (m :: * -> *) a. Monad m => a -> m a
return (HsRecFields GhcTcId (LPat GhcTcId) -> HsConPatDetails GhcTcId
forall arg rec. rec -> HsConDetails arg rec
RecCon ([LHsRecField GhcTcId (LPat GhcTcId)]
-> Maybe Int -> HsRecFields GhcTcId (LPat GhcTcId)
forall p arg. [LHsRecField p arg] -> Maybe Int -> HsRecFields p arg
HsRecFields [LHsRecField GhcTcId (LPat GhcTcId)]
rpats' Maybe Int
dd), r
res) }
where
tc_field :: Checker (LHsRecField GhcRn (LPat GhcRn))
(LHsRecField GhcTcId (LPat GhcTcId))
tc_field :: LHsRecField GhcRn (LPat GhcRn)
-> PatEnv -> TcM r -> TcM (LHsRecField GhcTcId (LPat GhcTcId), r)
tc_field (LHsRecField GhcRn (LPat GhcRn)
-> Located (SrcSpanLess (LHsRecField GhcRn (LPat GhcRn)))
forall a. HasSrcSpan a => a -> Located (SrcSpanLess a)
dL->L l :: SrcSpan
l (HsRecField (dL->L loc
(FieldOcc sel (dL->L lr rdr))) pat pun))
penv :: PatEnv
penv thing_inside :: TcM r
thing_inside
= do { TcId
sel' <- Name -> TcM TcId
tcLookupId Name
XCFieldOcc GhcRn
sel
; TcSigmaType
pat_ty <- SrcSpan -> TcM TcSigmaType -> TcM TcSigmaType
forall a. SrcSpan -> TcRn a -> TcRn a
setSrcSpan SrcSpan
loc (TcM TcSigmaType -> TcM TcSigmaType)
-> TcM TcSigmaType -> TcM TcSigmaType
forall a b. (a -> b) -> a -> b
$ Name -> FieldLabelString -> TcM TcSigmaType
find_field_ty Name
XCFieldOcc GhcRn
sel
(OccName -> FieldLabelString
occNameFS (OccName -> FieldLabelString) -> OccName -> FieldLabelString
forall a b. (a -> b) -> a -> b
$ RdrName -> OccName
rdrNameOcc SrcSpanLess (Located RdrName)
RdrName
rdr)
; (pat' :: LPat GhcTcId
pat', res :: r
res) <- (LPat GhcRn, TcSigmaType)
-> PatEnv -> TcM r -> TcM (LPat GhcTcId, r)
Checker (LPat GhcRn, TcSigmaType) (LPat GhcTcId)
tcConArg (LPat GhcRn
pat, TcSigmaType
pat_ty) PatEnv
penv TcM r
thing_inside
; (LHsRecField GhcTcId (LPat GhcTcId), r)
-> TcM (LHsRecField GhcTcId (LPat GhcTcId), r)
forall (m :: * -> *) a. Monad m => a -> m a
return (SrcSpan
-> SrcSpanLess (LHsRecField GhcTcId (LPat GhcTcId))
-> LHsRecField GhcTcId (LPat GhcTcId)
forall a. HasSrcSpan a => SrcSpan -> SrcSpanLess a -> a
cL SrcSpan
l (Located (FieldOcc GhcTcId)
-> LPat GhcTcId
-> Bool
-> HsRecField' (FieldOcc GhcTcId) (LPat GhcTcId)
forall id arg. Located id -> arg -> Bool -> HsRecField' id arg
HsRecField (SrcSpan
-> SrcSpanLess (Located (FieldOcc GhcTcId))
-> Located (FieldOcc GhcTcId)
forall a. HasSrcSpan a => SrcSpan -> SrcSpanLess a -> a
cL SrcSpan
loc (XCFieldOcc GhcTcId -> Located RdrName -> FieldOcc GhcTcId
forall pass. XCFieldOcc pass -> Located RdrName -> FieldOcc pass
FieldOcc TcId
XCFieldOcc GhcTcId
sel' (SrcSpan -> SrcSpanLess (Located RdrName) -> Located RdrName
forall a. HasSrcSpan a => SrcSpan -> SrcSpanLess a -> a
cL SrcSpan
lr SrcSpanLess (Located RdrName)
rdr))) LPat GhcTcId
pat'
Bool
pun), r
res) }
tc_field (LHsRecField GhcRn (LPat GhcRn)
-> Located (SrcSpanLess (LHsRecField GhcRn (LPat GhcRn)))
forall a. HasSrcSpan a => a -> Located (SrcSpanLess a)
dL->L _ (HsRecField (dL->L _ (XFieldOcc _)) _ _)) _ _
= String -> TcM (LHsRecField GhcTcId (LPat GhcTcId), r)
forall a. String -> a
panic "tcConArgs"
tc_field _ _ _ = String -> TcM (LHsRecField GhcTcId (LPat GhcTcId), r)
forall a. String -> a
panic "tc_field: Impossible Match"
find_field_ty :: Name -> FieldLabelString -> TcM TcType
find_field_ty :: Name -> FieldLabelString -> TcM TcSigmaType
find_field_ty sel :: Name
sel lbl :: FieldLabelString
lbl
= case [TcSigmaType
ty | (fl :: FieldLabel
fl, ty :: TcSigmaType
ty) <- [(FieldLabel, TcSigmaType)]
field_tys, FieldLabel -> Name
forall a. FieldLbl a -> a
flSelector FieldLabel
fl Name -> Name -> Bool
forall a. Eq a => a -> a -> Bool
== Name
sel] of
[] -> SDoc -> TcM TcSigmaType
forall a. SDoc -> TcRn a
failWith (ConLike -> FieldLabelString -> SDoc
badFieldCon ConLike
con_like FieldLabelString
lbl)
(pat_ty :: TcSigmaType
pat_ty : extras :: [TcSigmaType]
extras) -> do
String -> SDoc -> TcRn ()
traceTc "find_field" (TcSigmaType -> SDoc
forall a. Outputable a => a -> SDoc
ppr TcSigmaType
pat_ty SDoc -> SDoc -> SDoc
<+> [TcSigmaType] -> SDoc
forall a. Outputable a => a -> SDoc
ppr [TcSigmaType]
extras)
ASSERT( null extras ) (return pat_ty)
field_tys :: [(FieldLabel, TcType)]
field_tys :: [(FieldLabel, TcSigmaType)]
field_tys = [FieldLabel] -> [TcSigmaType] -> [(FieldLabel, TcSigmaType)]
forall a b. [a] -> [b] -> [(a, b)]
zip (ConLike -> [FieldLabel]
conLikeFieldLabels ConLike
con_like) [TcSigmaType]
arg_tys
tcConArg :: Checker (LPat GhcRn, TcSigmaType) (LPat GhcTc)
tcConArg :: (LPat GhcRn, TcSigmaType)
-> PatEnv -> TcM r -> TcM (LPat GhcTcId, r)
tcConArg (arg_pat :: LPat GhcRn
arg_pat, arg_ty :: TcSigmaType
arg_ty) penv :: PatEnv
penv thing_inside :: TcM r
thing_inside
= LPat GhcRn
-> ExpSigmaType -> PatEnv -> TcM r -> TcM (LPat GhcTcId, r)
forall a.
LPat GhcRn
-> ExpSigmaType -> PatEnv -> TcM a -> TcM (LPat GhcTcId, a)
tc_lpat LPat GhcRn
arg_pat (TcSigmaType -> ExpSigmaType
mkCheckExpType TcSigmaType
arg_ty) PatEnv
penv TcM r
thing_inside
addDataConStupidTheta :: DataCon -> [TcType] -> TcM ()
addDataConStupidTheta :: DataCon -> [TcSigmaType] -> TcRn ()
addDataConStupidTheta data_con :: DataCon
data_con inst_tys :: [TcSigmaType]
inst_tys
| [TcSigmaType] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [TcSigmaType]
stupid_theta = () -> TcRn ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
| Bool
otherwise = CtOrigin -> [TcSigmaType] -> TcRn ()
instStupidTheta CtOrigin
origin [TcSigmaType]
inst_theta
where
origin :: CtOrigin
origin = Name -> CtOrigin
OccurrenceOf (DataCon -> Name
dataConName DataCon
data_con)
stupid_theta :: [TcSigmaType]
stupid_theta = DataCon -> [TcSigmaType]
dataConStupidTheta DataCon
data_con
univ_tvs :: [TcId]
univ_tvs = DataCon -> [TcId]
dataConUnivTyVars DataCon
data_con
tenv :: TCvSubst
tenv = [TcId] -> [TcSigmaType] -> TCvSubst
HasDebugCallStack => [TcId] -> [TcSigmaType] -> TCvSubst
zipTvSubst [TcId]
univ_tvs ([TcId] -> [TcSigmaType] -> [TcSigmaType]
forall b a. [b] -> [a] -> [a]
takeList [TcId]
univ_tvs [TcSigmaType]
inst_tys)
inst_theta :: [TcSigmaType]
inst_theta = HasCallStack => TCvSubst -> [TcSigmaType] -> [TcSigmaType]
TCvSubst -> [TcSigmaType] -> [TcSigmaType]
substTheta TCvSubst
tenv [TcSigmaType]
stupid_theta
maybeWrapPatCtxt :: Pat GhcRn -> (TcM a -> TcM b) -> TcM a -> TcM b
maybeWrapPatCtxt :: LPat GhcRn -> (TcM a -> TcM b) -> TcM a -> TcM b
maybeWrapPatCtxt pat :: LPat GhcRn
pat tcm :: TcM a -> TcM b
tcm thing_inside :: TcM a
thing_inside
| Bool -> Bool
not (LPat GhcRn -> Bool
forall p. Pat p -> Bool
worth_wrapping LPat 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 _ = Bool
True
msg :: SDoc
msg = SDoc -> Int -> SDoc -> SDoc
hang (String -> SDoc
text "In the pattern:") 2 (LPat GhcRn -> SDoc
forall a. Outputable a => a -> SDoc
ppr LPat GhcRn
pat)
checkExistentials :: [TyVar]
-> [Type]
-> PatEnv -> TcM ()
checkExistentials :: [TcId] -> [TcSigmaType] -> PatEnv -> TcRn ()
checkExistentials ex_tvs :: [TcId]
ex_tvs tys :: [TcSigmaType]
tys _
| (TcId -> Bool) -> [TcId] -> Bool
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
all (Bool -> Bool
not (Bool -> Bool) -> (TcId -> Bool) -> TcId -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (TcId -> VarSet -> Bool
`elemVarSet` [TcSigmaType] -> VarSet
tyCoVarsOfTypes [TcSigmaType]
tys)) [TcId]
ex_tvs = () -> TcRn ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
checkExistentials _ _ (PE { pe_ctxt :: PatEnv -> PatCtxt
pe_ctxt = LetPat {}}) = () -> TcRn ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
checkExistentials _ _ (PE { pe_ctxt :: PatEnv -> PatCtxt
pe_ctxt = LamPat ProcExpr }) = SDoc -> TcRn ()
forall a. SDoc -> TcRn a
failWithTc SDoc
existentialProcPat
checkExistentials _ _ (PE { pe_lazy :: PatEnv -> Bool
pe_lazy = Bool
True }) = SDoc -> TcRn ()
forall a. SDoc -> TcRn a
failWithTc SDoc
existentialLazyPat
checkExistentials _ _ _ = () -> TcRn ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
existentialLazyPat :: SDoc
existentialLazyPat :: SDoc
existentialLazyPat
= SDoc -> Int -> SDoc -> SDoc
hang (String -> SDoc
text "An existential or GADT data constructor cannot be used")
2 (String -> SDoc
text "inside a lazy (~) pattern")
existentialProcPat :: SDoc
existentialProcPat :: SDoc
existentialProcPat
= String -> SDoc
text "Proc patterns cannot use existential or GADT data constructors"
badFieldCon :: ConLike -> FieldLabelString -> SDoc
badFieldCon :: ConLike -> FieldLabelString -> SDoc
badFieldCon con :: ConLike
con field :: FieldLabelString
field
= [SDoc] -> SDoc
hsep [String -> SDoc
text "Constructor" SDoc -> SDoc -> SDoc
<+> SDoc -> SDoc
quotes (ConLike -> SDoc
forall a. Outputable a => a -> SDoc
ppr ConLike
con),
String -> SDoc
text "does not have field", SDoc -> SDoc
quotes (FieldLabelString -> SDoc
forall a. Outputable a => a -> SDoc
ppr FieldLabelString
field)]
polyPatSig :: TcType -> SDoc
polyPatSig :: TcSigmaType -> SDoc
polyPatSig sig_ty :: TcSigmaType
sig_ty
= SDoc -> Int -> SDoc -> SDoc
hang (String -> SDoc
text "Illegal polymorphic type signature in pattern:")
2 (TcSigmaType -> SDoc
forall a. Outputable a => a -> SDoc
ppr TcSigmaType
sig_ty)