Skip to content

Commit 4bfd155

Browse files
committed
[ fix #460 ] if/then/else as first argument to infix needs parens
1 parent ca91a75 commit 4bfd155

3 files changed

Lines changed: 14 additions & 1 deletion

File tree

src/Agda2Hs/Language/Haskell/Utils.hs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,8 @@ uses ty = not . null . usedTypesOf ty
223223

224224
-- Ideally, our pretty-printing library should insert parenthesis where needed.
225225
-- However, hs-src-exts does not insert adequate parenthesis for infix
226-
-- operators so we need to insert some by hand (see issues #54 and #273 and #317).
226+
-- operators so we need to insert some by hand
227+
-- (see issues #54 and #273 and #317 and #460).
227228

228229
-- | Properly parenthesize an expression with regards to the default fixities.
229230
insertParens :: Data a => a -> a
@@ -254,6 +255,7 @@ insertPars fixs = \case
254255

255256
needParenExpr (InfixApp _ _ _ e2) = needParenExpr e2
256257
needParenExpr Lambda{} = True
258+
needParenExpr If{} = True
257259
needParenExpr _ = False
258260

259261
parL topOp e =

test/Succeed/Issue460.agda

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
open import Haskell.Prelude
2+
3+
prepend : Bool List Int List Int
4+
prepend b xs = (if b then 1 ∷ [] else []) ++ xs
5+
6+
{-# COMPILE AGDA2HS prepend #-}

test/Succeed/Issue460.hs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module Issue460 where
2+
3+
prepend :: Bool -> [Int] -> [Int]
4+
prepend b xs = (if b then [1] else []) ++ xs
5+

0 commit comments

Comments
 (0)