summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen Gamari <ben@smart-cactus.org>2016-12-23 18:09:40 -0500
committerBen Gamari <ben@smart-cactus.org>2016-12-23 18:09:40 -0500
commit48a5da9ac6abd42e713402bd38612ce6624cac1b (patch)
tree6b7e820bb912255f97876c87c1833ec630f0a803
parent2689a1692636521777f007861a484e7064b2d696 (diff)
downloadhaskell-48a5da9ac6abd42e713402bd38612ce6624cac1b.tar.gz
rename: Add note describing #11216
-rw-r--r--compiler/rename/RnExpr.hs26
1 files changed, 22 insertions, 4 deletions
diff --git a/compiler/rename/RnExpr.hs b/compiler/rename/RnExpr.hs
index 5427579793..811ecbafbe 100644
--- a/compiler/rename/RnExpr.hs
+++ b/compiler/rename/RnExpr.hs
@@ -763,6 +763,25 @@ rnStmtsWithFreeVars ctxt rnBody (lstmt@(L loc _) : lstmts) thing_inside
; return (((stmts1 ++ stmts2), thing), fvs) }
----------------------
+
+{-
+Note [Failing pattern matches in Stmts]
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+Many things desugar to HsStmts including monadic things like `do` and `mdo`
+statements, pattern guards, and list comprehensions (see 'HsStmtContext' for an
+exhaustive list). How we deal with pattern match failure is context-dependent.
+
+ * In the case of list comprehensions and pattern guards we don't need any 'fail'
+ function; the desugarer ignores the fail function field of 'BindStmt' entirely.
+ * In the case of monadic contexts (e.g. monad comprehensions, do, and mdo
+ expressions) we want pattern match failure to be desugared to the appropriate
+ 'fail' function (either that of Monad or MonadFail, depending on whether
+ -XMonadFailDesugaring is enabled.)
+
+At one point we failed to make this distinction, leading to #11216.
+-}
+
rnStmt :: Outputable (body RdrName)
=> HsStmtContext Name
-> (Located (body RdrName) -> RnM (Located (body Name), FreeVars))
@@ -805,13 +824,12 @@ rnStmt ctxt rnBody (L loc (BindStmt pat body _ _ _)) thing_inside
; xMonadFailEnabled <- fmap (xopt LangExt.MonadFailDesugaring) getDynFlags
; let getFailFunction
-- For non-monadic contexts (e.g. guard patterns, list
- -- comprehensions, etc.) we should not need to fail
+ -- comprehensions, etc.) we should not need to fail.
+ -- See Note [Failing pattern matches in Stmts]
| not (isMonadFailStmtContext ctxt)
- = return (err, emptyFVs)
+ = return (noSyntaxExpr, emptyFVs)
| xMonadFailEnabled = lookupSyntaxName failMName
| otherwise = lookupSyntaxName failMName_preMFP
- where err = pprPanic "rnStmt: fail function forced"
- (text "context:" <+> ppr ctxt)
; (fail_op, fvs2) <- getFailFunction
; rnPat (StmtCtxt ctxt) pat $ \ pat' -> do