@@ -412,7 +412,17 @@ p_hsLocalBinds = \case
412412 (Left <$> bagToList bag) ++ (Right <$> lsigs)
413413 p_item (Left x) = located x p_valDecl
414414 p_item (Right x) = located x p_sigDecl
415− sitcc $ sepSemi (useBraces . p_item) (sortOn ssStart items)
415+ -- Assigns 'False' to the last element, 'True' to the rest.
416+ markInit :: [a] -> [(Bool, a)]
417+ markInit [] = []
418+ markInit (x:[]) = [(False, x)]
419+ markInit (x:xs) = (True, x) : markInit xs
420+ -- NOTE When in a single-line layout, there is a chance that the inner
421+ -- elements will also contain semicolons and they will confuse the
422+ -- parser. so we request braces around every element except the last.
423+ sitcc $ sepSemi
424+ (\(m, i) -> (if m then useBraces else id) $ p_item i)
425+ (markInit $ sortOn ssStart items)
416426 HsValBinds NoExt _ -> notImplemented "HsValBinds"
417427 HsIPBinds NoExt (IPBinds NoExt xs) ->
418428 -- Second argument of IPBind is always Left before type-checking.
@@ -420,7 +430,7 @@ p_hsLocalBinds = \case
420430 atom name
421431 txt " ="
422432 breakpoint
423− dontUseBraces $ inci $ located expr p_hsExpr
433+ useBraces $ inci $ located expr p_hsExpr
424434 p_ipBind _ = notImplemented "XHsIPBinds"
425435 in sepSemi (located' p_ipBind) xs
426436 HsIPBinds NoExt _ -> notImplemented "HsIpBinds"
@@ -553,7 +563,7 @@ p_hsExpr = \case
553563 inci . sitcc $ sep newline (located' (p_grhs RightArrow)) guards
554564 HsLet NoExt localBinds e -> do
555565 txt "let "
556− sitcc (located localBinds p_hsLocalBinds)
566+ dontUseBraces $ sitcc (located localBinds p_hsLocalBinds)
557567 vlayout space (newline >> space)
558568 txt "in "
559569 sitcc (located e p_hsExpr)