diff --git a/compiler/src/formatting/fmt.re b/compiler/src/formatting/fmt.re index ad1bd2524..f64bfaf07 100644 --- a/compiler/src/formatting/fmt.re +++ b/compiler/src/formatting/fmt.re @@ -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 }; }; diff --git a/compiler/test/grainfmt/constraints.expected.gr b/compiler/test/grainfmt/constraints.expected.gr index 6f307c7fe..fb93f3e8e 100644 --- a/compiler/test/grainfmt/constraints.expected.gr +++ b/compiler/test/grainfmt/constraints.expected.gr @@ -8,3 +8,8 @@ let test = test => { print(i) }, test: List) } + +// Regression #2244 +(1: Number): Number + +((1: Number): Number): Number diff --git a/compiler/test/grainfmt/constraints.input.gr b/compiler/test/grainfmt/constraints.input.gr index 6f307c7fe..fb93f3e8e 100644 --- a/compiler/test/grainfmt/constraints.input.gr +++ b/compiler/test/grainfmt/constraints.input.gr @@ -8,3 +8,8 @@ let test = test => { print(i) }, test: List) } + +// Regression #2244 +(1: Number): Number + +((1: Number): Number): Number