Commit bf2411a3 authored by Vladislav Zavialov's avatar Vladislav Zavialov Committed by Marge Bot

Fix PostfixOperators (#18151)

This fixes a regression introduced in 2b89ca5b
See the new T18151x test case.
parent ac300a0d
Pipeline #26305 passed with stages
in 304 minutes and 5 seconds
......@@ -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
......
{-# LANGUAGE PostfixOperators #-}
import Control.Exception
data MyException = MyE
deriving (Show)
instance Exception MyException
(#) :: Bool -> Bool -> Bool
(#) = throw MyE
main = do
r <- try (evaluate (seq (True #) ()))
case r of
Left MyE -> putStrLn "PostfixOperators ok"
Right () -> putStrLn "PostfixOperators broken"
......@@ -65,6 +65,7 @@ test('T11747', normal, compile_and_run, ['-dcore-lint'])
test('T12595', normal, compile_and_run, [''])
test('T13285', normal, compile_and_run, [''])
test('T18151', normal, compile_and_run, [''])
test('T18151x', normal, compile_and_run, [''])
test('T18172', [], ghci_script, ['T18172.script'])
test('DsDoExprFailMsg', exit_code(1), compile_and_run, [''])
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment