-pprMatchContext (FunRhs fun _) = ptext (sLit "the definition of")
- <+> quotes (ppr fun)
-pprMatchContext CaseAlt = ptext (sLit "a case alternative")
-pprMatchContext RecUpd = ptext (sLit "a record-update construct")
-pprMatchContext ThPatQuote = ptext (sLit "a Template Haskell pattern quotation")
-pprMatchContext PatBindRhs = ptext (sLit "a pattern binding")
-pprMatchContext LambdaExpr = ptext (sLit "a lambda abstraction")
-pprMatchContext ProcExpr = ptext (sLit "an arrow abstraction")
-pprMatchContext (StmtCtxt ctxt) = ptext (sLit "a pattern binding in")
- $$ pprStmtContext ctxt
-
-pprStmtContext :: Outputable id => HsStmtContext id -> SDoc
+pprMatchContext ctxt
+ | want_an ctxt = ptext (sLit "an") <+> pprMatchContextNoun ctxt
+ | otherwise = ptext (sLit "a") <+> pprMatchContextNoun ctxt
+ where
+ want_an (FunRhs {}) = True -- Use "an" in front
+ want_an ProcExpr = True
+ want_an _ = False
+
+pprMatchContextNoun :: Outputable id => HsMatchContext id -> SDoc
+pprMatchContextNoun (FunRhs fun _) = ptext (sLit "equation for")
+ <+> quotes (ppr fun)
+pprMatchContextNoun CaseAlt = ptext (sLit "case alternative")
+pprMatchContextNoun RecUpd = ptext (sLit "record-update construct")
+pprMatchContextNoun ThPatQuote = ptext (sLit "Template Haskell pattern quotation")
+pprMatchContextNoun PatBindRhs = ptext (sLit "pattern binding")
+pprMatchContextNoun LambdaExpr = ptext (sLit "lambda abstraction")
+pprMatchContextNoun ProcExpr = ptext (sLit "arrow abstraction")
+pprMatchContextNoun (StmtCtxt ctxt) = ptext (sLit "pattern binding in")
+ $$ pprStmtContext ctxt
+
+-----------------
+pprAStmtContext, pprStmtContext :: Outputable id => HsStmtContext id -> SDoc
+pprAStmtContext ctxt = article <+> pprStmtContext ctxt
+ where
+ pp_an = ptext (sLit "an")
+ pp_a = ptext (sLit "a")
+ article = case ctxt of
+ MDoExpr -> pp_an
+ PArrComp -> pp_an
+ GhciStmt -> pp_an
+ _ -> pp_a
+
+
+-----------------
+pprStmtContext GhciStmt = ptext (sLit "interactive GHCi command")
+pprStmtContext DoExpr = ptext (sLit "'do' block")
+pprStmtContext MDoExpr = ptext (sLit "'mdo' block")
+pprStmtContext ArrowExpr = ptext (sLit "'do' block in an arrow command")
+pprStmtContext ListComp = ptext (sLit "list comprehension")
+pprStmtContext MonadComp = ptext (sLit "monad comprehension")
+pprStmtContext PArrComp = ptext (sLit "array comprehension")
+pprStmtContext (PatGuard ctxt) = ptext (sLit "pattern guard for") $$ pprMatchContext ctxt
+
+-- Drop the inner contexts when reporting errors, else we get
+-- Unexpected transform statement
+-- in a transformed branch of
+-- transformed branch of
+-- transformed branch of monad comprehension