Skip to content

Commit

Permalink
fix(grainfmt): handle empty type for foreign exports (grain-lang#907)
Browse files Browse the repository at this point in the history
Handle printing when the type is (). Use a switch and update the test
  • Loading branch information
marcusroberts authored Sep 19, 2021
1 parent 4acb91f commit d3b60a4
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
9 changes: 5 additions & 4 deletions compiler/grainformat/reformat.re
Original file line number Diff line number Diff line change
Expand Up @@ -933,9 +933,10 @@ and print_type =
| PTyArrow(types, parsed_type) =>
Doc.concat([
Doc.group(
if (List.length(types) == 1) {
print_type(List.hd(types), original_source);
} else {
switch (List.length(types)) {
| 0 => Doc.concat([Doc.lparen, Doc.rparen])
| 1 => print_type(List.hd(types), original_source)
| _ =>
Doc.concat([
Doc.lparen,
Doc.indent(
Expand All @@ -949,7 +950,7 @@ and print_type =
),
Doc.softLine,
Doc.rparen,
]);
])
},
),
Doc.space,
Expand Down
2 changes: 2 additions & 0 deletions compiler/test/formatter_inputs/imports.gr
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,5 @@ import * except {
and
// just because
} from "runtime/unsafe/wasmi32"

export foreign wasm promise_results_count: () -> WasmI64 as promiseResultsCount from "env"
2 changes: 2 additions & 0 deletions compiler/test/formatter_outputs/imports.gr
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,5 @@ import * except {
and
// just because
} from "runtime/unsafe/wasmi32"

export foreign wasm promise_results_count: () -> WasmI64 as promiseResultsCount from "env"

0 comments on commit d3b60a4

Please sign in to comment.