summaryrefslogtreecommitdiff
path: root/compiler/deSugar/Match.hs
diff options
context:
space:
mode:
authorSimon Peyton Jones <simonpj@microsoft.com>2016-09-16 22:33:20 +0100
committerSimon Peyton Jones <simonpj@microsoft.com>2016-09-30 12:53:20 +0100
commit2fbfbca2d12a8e9a09627529cf4f8284b19023ff (patch)
tree2c5b345ebc9d46e45488ace751f554f154ffafd6 /compiler/deSugar/Match.hs
parent0b533a2597a8c5d5b623a008378af39826b009db (diff)
downloadhaskell-2fbfbca2d12a8e9a09627529cf4f8284b19023ff.tar.gz
Fix desugaring of pattern bindings (again)
This patch fixes Trac #12595. The problem was with a pattern binding like !x = e For a start it's silly to match that pattern and build a unit tuple (the General Case of mkSelectorBinds); but that's what was happening because the bang fell through to the general case. But for a variable pattern building any auxiliary bindings is stupid. So the patch introduces a new case in mkSelectorBinds for variable patterns. Then it turned out that if 'e' was a plain variable, and moreover was imported GlobalId, then matchSinglePat made it a /bound/ variable, which should never happen. That ultimately caused a linker error, but the original bug was much earlier.
Diffstat (limited to 'compiler/deSugar/Match.hs')
-rw-r--r--compiler/deSugar/Match.hs21
1 files changed, 16 insertions, 5 deletions
diff --git a/compiler/deSugar/Match.hs b/compiler/deSugar/Match.hs
index 93d43c8d26..288fc40f45 100644
--- a/compiler/deSugar/Match.hs
+++ b/compiler/deSugar/Match.hs
@@ -763,12 +763,27 @@ matchSimply scrut hs_ctx pat result_expr fail_expr = do
matchSinglePat :: CoreExpr -> HsMatchContext Name -> LPat Id
-> Type -> MatchResult -> DsM MatchResult
--- Do not warn about incomplete patterns
+-- matchSinglePat does not warn about incomplete patterns
-- Used for things like [ e | pat <- stuff ], where
-- incomplete patterns are just fine
+
matchSinglePat (Var var) ctx pat ty match_result
+ | isLocalId var
+ = match_single_pat_var var ctx pat ty match_result
+
+matchSinglePat scrut hs_ctx pat ty match_result
+ = do { var <- selectSimpleMatchVarL pat
+ ; match_result' <- match_single_pat_var var hs_ctx pat ty match_result
+ ; return (adjustMatchResult (bindNonRec var scrut) match_result') }
+
+match_single_pat_var :: Id -> HsMatchContext Name -> LPat Id
+ -> Type -> MatchResult -> DsM MatchResult
+-- matchSinglePat ensures that the scrutinee is a variable
+-- and then calls match_single_pat_var
+match_single_pat_var var ctx pat ty match_result
= do { dflags <- getDynFlags
; locn <- getSrcSpanDs
+
-- Pattern match check warnings
; checkSingle dflags (DsMatchContext ctx locn) var (unLoc pat)
@@ -776,10 +791,6 @@ matchSinglePat (Var var) ctx pat ty match_result
, eqn_rhs = match_result }
; match [var] ty [eqn_info] }
-matchSinglePat scrut hs_ctx pat ty match_result
- = do { var <- selectSimpleMatchVarL pat
- ; match_result' <- matchSinglePat (Var var) hs_ctx pat ty match_result
- ; return (adjustMatchResult (bindNonRec var scrut) match_result') }
{-