Skip to content

Commit

Permalink
fix(grainfmt): Fix formatting of default argument types (#2081)
Browse files Browse the repository at this point in the history
  • Loading branch information
spotandjake committed Mar 29, 2024
1 parent 520dd8a commit 0c15e4a
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
15 changes: 13 additions & 2 deletions compiler/src/formatting/fmt.re
Expand Up @@ -2538,8 +2538,7 @@ let print_parsed_type_argument = (fmt, arg) => {
(
switch (arg.ptyp_arg_label) {
| Unlabeled => empty
| Labeled({txt: label, loc: label_loc})
| Default({txt: label, loc: label_loc}) =>
| Labeled({txt: label, loc: label_loc}) =>
string(label)
++ string(":")
++ fmt.print_comment_range(
Expand All @@ -2550,6 +2549,18 @@ let print_parsed_type_argument = (fmt, arg) => {
label_loc,
arg.ptyp_arg_type.ptyp_loc,
)
| Default({txt: label, loc: label_loc}) =>
string("?")
++ string(label)
++ string(":")
++ fmt.print_comment_range(
fmt,
~none=space,
~lead=space,
~trail=space,
label_loc,
arg.ptyp_arg_type.ptyp_loc,
)
}
)
++ fmt.print_type(fmt, arg.ptyp_arg_type);
Expand Down
2 changes: 2 additions & 0 deletions compiler/test/grainfmt/function_params.expected.gr
Expand Up @@ -39,3 +39,5 @@ let stringTailMatcher = (toMatch, len) =>
}

let f: Number => (Number, Number) => Number = a => (b, c) => a + b + c

let namedArg: (?suffix: String) => String = (suffix="") => suffix
2 changes: 2 additions & 0 deletions compiler/test/grainfmt/function_params.input.gr
Expand Up @@ -34,3 +34,5 @@ let stringTailMatcher = (toMatch, len) =>
}

let f: Number -> (Number, Number) -> Number = a => (b, c) => a + b + c

let namedArg: (?suffix: String) => String = (suffix="") => suffix

0 comments on commit 0c15e4a

Please sign in to comment.