diff options
author | Simon Peyton Jones <simonpj@microsoft.com> | 2018-09-20 20:02:39 +0100 |
---|---|---|
committer | Simon Peyton Jones <simonpj@microsoft.com> | 2018-09-23 02:45:23 +0100 |
commit | 4bde71df9a32bf6f5ee7d44fbbf79523da4b0a9e (patch) | |
tree | a629d95f46f0e0c80279168f855b5ac4e36d07e5 /compiler/hsSyn/HsExpr.hs | |
parent | cad5d0b69bc039b635a6eb0e5c9ed47d7c5a38ed (diff) | |
download | haskell-4bde71df9a32bf6f5ee7d44fbbf79523da4b0a9e.tar.gz |
Don't look up unnecessary return in LastStmt
This fixes Trac #15607. The general pattern is well
established (e.g. see the guard_op binding in rnStmt
of BodyStme), but we weren't using it for LastStmt.
Diffstat (limited to 'compiler/hsSyn/HsExpr.hs')
-rw-r--r-- | compiler/hsSyn/HsExpr.hs | 37 |
1 files changed, 20 insertions, 17 deletions
diff --git a/compiler/hsSyn/HsExpr.hs b/compiler/hsSyn/HsExpr.hs index 61285ba0c6..45b1b07d73 100644 --- a/compiler/hsSyn/HsExpr.hs +++ b/compiler/hsSyn/HsExpr.hs @@ -1241,7 +1241,7 @@ hsExprNeedsParens p = go go (HsMultiIf{}) = p > topPrec go (HsLet{}) = p > topPrec go (HsDo _ sc _) - | isListCompExpr sc = False + | isComprehensionContext sc = False | otherwise = p > topPrec go (ExplicitList{}) = False go (RecordUpd{}) = False @@ -1855,18 +1855,17 @@ type GhciStmt id = Stmt id (LHsExpr id) -- For details on above see note [Api annotations] in ApiAnnotation data StmtLR idL idR body -- body should always be (LHs**** idR) = LastStmt -- Always the last Stmt in ListComp, MonadComp, - -- and (after the renamer) DoExpr, MDoExpr + -- and (after the renamer, see RnExpr.checkLastStmt) DoExpr, MDoExpr -- Not used for GhciStmtCtxt, PatGuard, which scope over other stuff (XLastStmt idL idR body) body Bool -- True <=> return was stripped by ApplicativeDo - (SyntaxExpr idR) -- The return operator, used only for - -- MonadComp For ListComp we - -- use the baked-in 'return' For DoExpr, - -- MDoExpr, we don't apply a 'return' at - -- all See Note [Monad Comprehensions] | - -- - 'ApiAnnotation.AnnKeywordId' : - -- 'ApiAnnotation.AnnLarrow' + (SyntaxExpr idR) -- The return operator + -- The return operator is used only for MonadComp + -- For ListComp we use the baked-in 'return' + -- For DoExpr, MDoExpr, we don't apply a 'return' at all + -- See Note [Monad Comprehensions] + -- - 'ApiAnnotation.AnnKeywordId' : 'ApiAnnotation.AnnLarrow' -- For details on above see note [Api annotations] in ApiAnnotation | BindStmt (XBindStmt idL idR body) -- Post typechecking, @@ -2752,13 +2751,13 @@ data HsStmtContext id deriving Functor deriving instance (Data id) => Data (HsStmtContext id) -isListCompExpr :: HsStmtContext id -> Bool --- Uses syntax [ e | quals ] -isListCompExpr ListComp = True -isListCompExpr MonadComp = True -isListCompExpr (ParStmtCtxt c) = isListCompExpr c -isListCompExpr (TransStmtCtxt c) = isListCompExpr c -isListCompExpr _ = False +isComprehensionContext :: HsStmtContext id -> Bool +-- Uses comprehension syntax [ e | quals ] +isComprehensionContext ListComp = True +isComprehensionContext MonadComp = True +isComprehensionContext (ParStmtCtxt c) = isComprehensionContext c +isComprehensionContext (TransStmtCtxt c) = isComprehensionContext c +isComprehensionContext _ = False -- | Should pattern match failure in a 'HsStmtContext' be desugared using -- 'MonadFail'? @@ -2771,6 +2770,10 @@ isMonadFailStmtContext (ParStmtCtxt ctxt) = isMonadFailStmtContext ctxt isMonadFailStmtContext (TransStmtCtxt ctxt) = isMonadFailStmtContext ctxt isMonadFailStmtContext _ = False -- ListComp, PatGuard, ArrowExpr +isMonadCompContext :: HsStmtContext id -> Bool +isMonadCompContext MonadComp = True +isMonadCompContext _ = False + matchSeparator :: HsMatchContext id -> SDoc matchSeparator (FunRhs {}) = text "=" matchSeparator CaseAlt = text "->" @@ -2893,7 +2896,7 @@ pprStmtInCtxt :: (OutputableBndrId (GhcPass idL), -> StmtLR (GhcPass idL) (GhcPass idR) body -> SDoc pprStmtInCtxt ctxt (LastStmt _ e _ _) - | isListCompExpr ctxt -- For [ e | .. ], do not mutter about "stmts" + | isComprehensionContext ctxt -- For [ e | .. ], do not mutter about "stmts" = hang (text "In the expression:") 2 (ppr e) pprStmtInCtxt ctxt stmt |