Skip to content

Commit 0c15e4a

Browse files
authored
fix(grainfmt): Fix formatting of default argument types (#2081)
1 parent 520dd8a commit 0c15e4a

File tree

3 files changed

+17
-2
lines changed

3 files changed

+17
-2
lines changed

compiler/src/formatting/fmt.re

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2538,8 +2538,7 @@ let print_parsed_type_argument = (fmt, arg) => {
25382538
(
25392539
switch (arg.ptyp_arg_label) {
25402540
| Unlabeled => empty
2541-
| Labeled({txt: label, loc: label_loc})
2542-
| Default({txt: label, loc: label_loc}) =>
2541+
| Labeled({txt: label, loc: label_loc}) =>
25432542
string(label)
25442543
++ string(":")
25452544
++ fmt.print_comment_range(
@@ -2550,6 +2549,18 @@ let print_parsed_type_argument = (fmt, arg) => {
25502549
label_loc,
25512550
arg.ptyp_arg_type.ptyp_loc,
25522551
)
2552+
| Default({txt: label, loc: label_loc}) =>
2553+
string("?")
2554+
++ string(label)
2555+
++ string(":")
2556+
++ fmt.print_comment_range(
2557+
fmt,
2558+
~none=space,
2559+
~lead=space,
2560+
~trail=space,
2561+
label_loc,
2562+
arg.ptyp_arg_type.ptyp_loc,
2563+
)
25532564
}
25542565
)
25552566
++ fmt.print_type(fmt, arg.ptyp_arg_type);

compiler/test/grainfmt/function_params.expected.gr

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,5 @@ let stringTailMatcher = (toMatch, len) =>
3939
}
4040

4141
let f: Number => (Number, Number) => Number = a => (b, c) => a + b + c
42+
43+
let namedArg: (?suffix: String) => String = (suffix="") => suffix

compiler/test/grainfmt/function_params.input.gr

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,5 @@ let stringTailMatcher = (toMatch, len) =>
3434
}
3535

3636
let f: Number -> (Number, Number) -> Number = a => (b, c) => a + b + c
37+
38+
let namedArg: (?suffix: String) => String = (suffix="") => suffix

0 commit comments

Comments
 (0)