import CmdLineOpts ( DynFlag(..), dopt )
import HsSyn
-import TcHsSyn ( TypecheckedPat, TypecheckedMatch )
-import DsHsSyn ( outPatType )
+import TcHsSyn ( TypecheckedPat, TypecheckedMatch, TypecheckedMatchContext, outPatType )
import Check ( check, ExhaustivePat )
import CoreSyn
import CoreUtils ( bindNonRec )
import MatchCon ( matchConFamily )
import MatchLit ( matchLiterals )
import PrelInfo ( pAT_ERROR_ID )
-import Type ( splitAlgTyConApp, mkTyVarTys, Type )
+import TcType ( mkTyVarTys, Type, tcTyConAppArgs, tcEqType )
import TysWiredIn ( nilDataCon, consDataCon, mkTupleTy, mkListTy, tupleCon )
import BasicTypes ( Boxity(..) )
import UniqSet
= dontAddErrLoc (ptext SLIT("Some match(es)") <+> hang msg 8 (rest_of_msg_fun id))
pp_context (DsMatchContext kind pats loc) msg rest_of_msg_fun
- = addWarnLocHdrLine loc message (nest 8 (rest_of_msg_fun pref))
+ = addWarnLocHdrLine loc
+ (ptext SLIT("Pattern match(es)") <+> msg)
+ (sep [ppr_match <> char ':', nest 4 (rest_of_msg_fun pref)])
where
(ppr_match, pref)
= case kind of
FunRhs fun -> (pprMatchContext kind, \ pp -> ppr fun <+> pp)
other -> (pprMatchContext kind <+> ppr_pats pats, \ pp -> pp)
-
- message = ptext SLIT("Pattern match(es)") <+> msg <+> ppr_match <> char ':'
ppr_pats pats = sep (map ppr pats)
pats = map mk_pat tagged_arg_tys
-- Boring stuff to find the arg-tys of the constructor
- (_, inst_tys, _) = splitAlgTyConApp pat_ty
+ inst_tys = tcTyConAppArgs pat_ty -- Newtypes must be opaque
con_arg_tys' = dataConInstOrigArgTys data_con (inst_tys ++ mkTyVarTys ex_tvs)
tagged_arg_tys = con_arg_tys' `zip` (dataConFieldLabels data_con)
\end{enumerate}
\begin{code}
-matchWrapper :: HsMatchContext -- For shadowing warning messages
+matchWrapper :: TypecheckedMatchContext -- For shadowing warning messages
-> [TypecheckedMatch] -- Matches being desugared
- -> String -- Error message if the match fails
-> DsM ([Id], CoreExpr) -- Results
\end{code}
JJQC 30-Nov-1997
\begin{code}
-matchWrapper kind matches error_string
+matchWrapper ctxt matches
= getDOptsDs `thenDs` \ dflags ->
- flattenMatches kind matches `thenDs` \ (result_ty, eqns_info) ->
+ flattenMatches ctxt matches `thenDs` \ (result_ty, eqns_info) ->
let
EqnInfo _ _ arg_pats _ : _ = eqns_info
+ error_string = matchContextErrString ctxt
in
mapDs selectMatchVar arg_pats `thenDs` \ new_vars ->
match_fun dflags new_vars eqns_info `thenDs` \ match_result ->
extractMatchResult match_result fail_expr `thenDs` \ result_expr ->
returnDs (new_vars, result_expr)
where match_fun dflags
- = case kind of
+ = case ctxt of
LambdaExpr | dopt Opt_WarnSimplePatterns dflags -> matchExport
| otherwise -> match
_ -> matchExport
pattern. It returns an expression.
\begin{code}
-matchSimply :: CoreExpr -- Scrutinee
- -> HsMatchContext -- Match kind
- -> TypecheckedPat -- Pattern it should match
- -> CoreExpr -- Return this if it matches
- -> CoreExpr -- Return this if it doesn't
+matchSimply :: CoreExpr -- Scrutinee
+ -> TypecheckedMatchContext -- Match kind
+ -> TypecheckedPat -- Pattern it should match
+ -> CoreExpr -- Return this if it matches
+ -> CoreExpr -- Return this if it doesn't
-> DsM CoreExpr
matchSimply scrut kind pat result_expr fail_expr
This is actually local to @matchWrapper@.
\begin{code}
-flattenMatches :: HsMatchContext
+flattenMatches :: TypecheckedMatchContext
-> [TypecheckedMatch]
-> DsM (Type, [EquationInfo])
let
result_ty = head result_tys
in
- ASSERT( all (== result_ty) result_tys )
+ ASSERT( all (tcEqType result_ty) result_tys )
returnDs (result_ty, eqn_infos)
where
flatten_match (Match _ pats _ grhss, n)