diff --git a/src/Juvix/Compiler/Concrete/Print/Base.hs b/src/Juvix/Compiler/Concrete/Print/Base.hs index c44aead302..548a4b03cc 100644 --- a/src/Juvix/Compiler/Concrete/Print/Base.hs +++ b/src/Juvix/Compiler/Concrete/Print/Base.hs @@ -1014,11 +1014,18 @@ instance PrettyPrint PatternArg where ppCode PatternArg {..} = do let name' = ppCode <$> _patternArgName pat' = ppCode _patternArgPattern - (name' <&> (<> ppCode Kw.kwAt)) - ?<> delimIf _patternArgIsImplicit delimCond pat' - where - delimCond :: Bool - delimCond = isJust _patternArgName && not (isAtomic _patternArgPattern) + + let delimCond :: Bool + delimCond = isJust _patternArgName && not (isAtomic _patternArgPattern) + + asPatternInfo = + ((name' <&> (<> ppCode Kw.kwAt)) ?<>) + . if delimCond then parens else id + + case _patternArgIsImplicit of + Explicit -> asPatternInfo pat' + ImplicitInstance -> doubleBraces . asPatternInfo $ pat' + Implicit -> braces . asPatternInfo $ pat' instance PrettyPrint Text where ppCode = noLoc . pretty diff --git a/tests/positive/Format.juvix b/tests/positive/Format.juvix index 5b1be1c75a..fdd58e002e 100644 --- a/tests/positive/Format.juvix +++ b/tests/positive/Format.juvix @@ -374,4 +374,16 @@ l4 : List (List Int) := ; longLongLongListArg ]; +-- Format as-pattern interacting with implicit args. + +implicitWithInnerParens : {_ : Nat} -> Nat + | {A@(suc B@(suc x))} := x + | {B@(suc x)} := B + | {_} := zero; + +i2479' : {_ : Nat} -> Nat + | {suc (suc x)} := x + | {suc x} := x + | {_} := zero; + -- Comment at the end of a module