Skip to content

Commit

Permalink
fix(grainfmt): Correct formatting of nested constraints (#2245)
Browse files Browse the repository at this point in the history
  • Loading branch information
spotandjake authored Feb 16, 2025
1 parent 2f16ba5 commit bdb7f7c
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
7 changes: 7 additions & 0 deletions compiler/src/formatting/fmt.re
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,13 @@ let needs_grouping = (~parent, ~side: infix_side, expr) => {
| (PExpConstant(PConstNumber(PConstNumberRational(_))), _)
when op_precedence('/') <= precedence(parent) =>
ParenGrouping
| (PExpConstraint(_, _), _)
when
switch (parent.pexp_desc) {
| PExpConstraint(_, _) => true
| _ => false
} =>
ParenGrouping
| _ => FormatterGrouping
};
};
Expand Down
5 changes: 5 additions & 0 deletions compiler/test/grainfmt/constraints.expected.gr
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,8 @@ let test = test => {
print(i)
}, test: List<Number>)
}

// Regression #2244
(1: Number): Number

((1: Number): Number): Number
5 changes: 5 additions & 0 deletions compiler/test/grainfmt/constraints.input.gr
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,8 @@ let test = test => {
print(i)
}, test: List<Number>)
}

// Regression #2244
(1: Number): Number

((1: Number): Number): Number

0 comments on commit bdb7f7c

Please sign in to comment.