summaryrefslogtreecommitdiff
path: root/compiler
diff options
context:
space:
mode:
authorVladislav Zavialov <vlad.z.4096@gmail.com>2020-10-13 15:08:31 +0300
committerVladislav Zavialov <vlad.z.4096@gmail.com>2020-10-13 20:37:30 +0300
commitdb665fd671c23fb79b35f4a902d792dbb32f3531 (patch)
tree15396ace20eb18d38c5f2c665ea6ea22cb13a8d3 /compiler
parent2ca1f851fff953d433282ece7146f2fb4f638e59 (diff)
downloadhaskell-wip/postfix-operators.tar.gz
Fix PostfixOperators (#18151)wip/postfix-operators
This fixes a regression introduced in 2b89ca5b850b4097447cc4908cbb0631011ce979 See the new T18151x test case.
Diffstat (limited to 'compiler')
-rw-r--r--compiler/GHC/HsToCore/Expr.hs15
1 files changed, 14 insertions, 1 deletions
diff --git a/compiler/GHC/HsToCore/Expr.hs b/compiler/GHC/HsToCore/Expr.hs
index c9868cc381..24b4a76892 100644
--- a/compiler/GHC/HsToCore/Expr.hs
+++ b/compiler/GHC/HsToCore/Expr.hs
@@ -70,6 +70,8 @@ import GHC.Utils.Panic
import GHC.Core.PatSyn
import Control.Monad
+import qualified GHC.LanguageExtensions as LangExt
+
{-
************************************************************************
* *
@@ -347,7 +349,11 @@ converting to core it must become a CO.
Note [Desugaring operator sections]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-At first it looks as if we can convert
+Desugaring left sections with -XPostfixOperators is straightforward: convert
+(expr `op`) to (op expr).
+
+Without -XPostfixOperators it's a bit more tricky. At first it looks as if we
+can convert
(expr `op`)
@@ -398,6 +404,13 @@ dsExpr e@(OpApp _ e1 op e2)
-- See Note [Desugaring operator sections].
-- N.B. this also must handle postfix operator sections due to -XPostfixOperators.
dsExpr e@(SectionL _ expr op) = do
+ postfix_operators <- xoptM LangExt.PostfixOperators
+ if postfix_operators then
+ -- Desugar (e !) to ((!) e)
+ do { op' <- dsLExpr op
+ ; dsWhenNoErrs (dsLExprNoLP expr) $ \expr' ->
+ mkCoreAppDs (text "sectionl" <+> ppr expr) op' expr' }
+ else do
core_op <- dsLExpr op
x_core <- dsLExpr expr
case splitFunTys (exprType core_op) of