From 13ac7fadc031039aa3661054161c3b1b5e3b1564 Mon Sep 17 00:00:00 2001 From: Spotandjake <40705786+spotandjake@users.noreply.github.com> Date: Thu, 16 Jan 2025 21:35:32 -0500 Subject: [PATCH] fix(grainfmt): Fix formatting of function types with a single tuple arg (#2230) --- compiler/src/formatting/fmt.re | 13 ++++++++++++- compiler/test/grainfmt/lambda.expected.gr | 3 +++ compiler/test/grainfmt/lambda.input.gr | 3 +++ 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/compiler/src/formatting/fmt.re b/compiler/src/formatting/fmt.re index d384c0b823..adf8bb919a 100644 --- a/compiler/src/formatting/fmt.re +++ b/compiler/src/formatting/fmt.re @@ -2696,7 +2696,18 @@ let print_type = (fmt, {ptyp_desc, ptyp_loc}) => { ) ++ break, ) - | PTyArrow([{ptyp_arg_label: Unlabeled} as param], return) => + | PTyArrow( + [ + { + ptyp_arg_label: Unlabeled, + ptyp_arg_type: { + ptyp_desc: + PTyAny | PTyVar(_) | PTyArrow(_, _) | PTyConstr(_, []), + }, + } as param, + ], + return, + ) => fmt.print_parsed_type_argument(fmt, param) ++ string(" =>") ++ fmt.print_comment_range( diff --git a/compiler/test/grainfmt/lambda.expected.gr b/compiler/test/grainfmt/lambda.expected.gr index 1953857e98..56c9067299 100644 --- a/compiler/test/grainfmt/lambda.expected.gr +++ b/compiler/test/grainfmt/lambda.expected.gr @@ -9,6 +9,9 @@ y => { let z = 2 } +// Regression #2229 +let foo: ((a, b)) => Void = a => void + let testfna = forEachCodePoint(c => /* arg */ void) let testfn = forEachCodePoint(c => /* arg */ { diff --git a/compiler/test/grainfmt/lambda.input.gr b/compiler/test/grainfmt/lambda.input.gr index aa1e62f751..9b0e172f16 100644 --- a/compiler/test/grainfmt/lambda.input.gr +++ b/compiler/test/grainfmt/lambda.input.gr @@ -7,6 +7,9 @@ y => { let z = 2 } +// Regression #2229 +let foo: ((a, b)) => Void = a => void + let testfna = forEachCodePoint(c /* arg */ => void) let testfn = forEachCodePoint(c /* arg */ => {