diff --git a/compiler/fmt/src/pattern.rs b/compiler/fmt/src/pattern.rs index e4f53fc47c..4df623dd5c 100644 --- a/compiler/fmt/src/pattern.rs +++ b/compiler/fmt/src/pattern.rs @@ -85,20 +85,22 @@ impl<'a> Formattable for Pattern<'a> { RecordDestructure(loc_patterns) => { buf.indent(indent); buf.push_str("{"); - buf.spaces(1); - let mut it = loc_patterns.iter().peekable(); + if !loc_patterns.is_empty() { + buf.spaces(1); + let mut it = loc_patterns.iter().peekable(); + while let Some(loc_pattern) = it.next() { + loc_pattern.format(buf, indent); - while let Some(loc_pattern) = it.next() { - loc_pattern.format(buf, indent); - - if it.peek().is_some() { - buf.push_str(","); - buf.spaces(1); + if it.peek().is_some() { + buf.push_str(","); + buf.spaces(1); + } } + buf.spaces(1); } - buf.push_str(" }"); + buf.push_str("}"); } RequiredField(name, loc_pattern) => { diff --git a/compiler/fmt/tests/test_fmt.rs b/compiler/fmt/tests/test_fmt.rs index 985d4cbc28..3f3c25033c 100644 --- a/compiler/fmt/tests/test_fmt.rs +++ b/compiler/fmt/tests/test_fmt.rs @@ -2727,6 +2727,61 @@ mod test_fmt { #[test] fn empty_record() { expr_formats_same("{}"); + expr_formats_to("{ }", "{}"); + } + + #[test] + fn empty_record_patterns() { + expr_formats_to( + indoc!( + r#" + f = \{ } -> "Hello World" + + f + "# + ), + indoc!( + r#" + f = \{} -> "Hello World" + + f + "# + ), + ); + + expr_formats_to( + indoc!( + r#" + f = \a, b -> { } + + f + "# + ), + indoc!( + r#" + f = \a, b -> {} + + f + "# + ), + ); + + expr_formats_to( + indoc!( + r#" + { } <- f a b + + {} + "# + ), + indoc!( + r#" + {} <- f a b + + {} + "# + ), + ); } #[test] diff --git a/examples/benchmarks/AStar.roc b/examples/benchmarks/AStar.roc index d6aec65d8f..00da5a6634 100644 --- a/examples/benchmarks/AStar.roc +++ b/examples/benchmarks/AStar.roc @@ -78,7 +78,7 @@ updateCost = \current, neighbor, model -> astar : (position, position -> F64), (position -> Set position), position, Model position -> Result (List position) {} astar = \costFn, moveFn, goal, model -> when cheapestOpen (\source -> costFn source goal) model is - Err { } -> + Err {} -> Err {} Ok current -> diff --git a/examples/benchmarks/RBTreeInsert.roc b/examples/benchmarks/RBTreeInsert.roc index 442bbdefff..079353f3a1 100644 --- a/examples/benchmarks/RBTreeInsert.roc +++ b/examples/benchmarks/RBTreeInsert.roc @@ -13,7 +13,7 @@ main = |> Task.putLine show : RedBlackTree I64 {} -> Str -show = \tree -> showRBTree tree Num.toStr (\{ } -> "{}") +show = \tree -> showRBTree tree Num.toStr (\{} -> "{}") showRBTree : RedBlackTree k v, (k -> Str), (v -> Str) -> Str showRBTree = \tree, showKey, showValue -> diff --git a/examples/benchmarks/platform/Task.roc b/examples/benchmarks/platform/Task.roc index 1cc96bc6c5..d029385878 100644 --- a/examples/benchmarks/platform/Task.roc +++ b/examples/benchmarks/platform/Task.roc @@ -6,7 +6,7 @@ Task ok err : Effect.Effect (Result ok err) forever : Task val err -> Task * err forever = \task -> - looper = \{ } -> + looper = \{} -> task |> Effect.map \res -> diff --git a/examples/false-interpreter/False.roc b/examples/false-interpreter/False.roc index 537d794a18..8821364786 100644 --- a/examples/false-interpreter/False.roc +++ b/examples/false-interpreter/False.roc @@ -200,7 +200,7 @@ interpretCtxLoop = \ctx -> # `"` end of string when Str.fromUtf8 bytes is Ok str -> - { } <- Task.await (Stdout.raw str) + {} <- Task.await (Stdout.raw str) Task.succeed (Step { newCtx & state: Executing }) Err _ -> @@ -481,7 +481,7 @@ stepExecCtx = \ctx, char -> Ok (T popCtx num) -> when Str.fromUtf8 [ Num.intCast num ] is Ok str -> - { } <- Task.await (Stdout.raw str) + {} <- Task.await (Stdout.raw str) Task.succeed popCtx Err _ -> @@ -494,7 +494,7 @@ stepExecCtx = \ctx, char -> # `.` write int when popNumber ctx is Ok (T popCtx num) -> - { } <- Task.await (Stdout.raw (Num.toStr (Num.intCast num))) + {} <- Task.await (Stdout.raw (Num.toStr (Num.intCast num))) Task.succeed popCtx Err e -> diff --git a/examples/false-interpreter/platform/File.roc b/examples/false-interpreter/platform/File.roc index e64efe749a..7ad1f8c4aa 100644 --- a/examples/false-interpreter/platform/File.roc +++ b/examples/false-interpreter/platform/File.roc @@ -23,5 +23,5 @@ withOpen : Str, (Handle -> Task {} a) -> Task {} a withOpen = \path, callback -> handle <- Task.await (open path) result <- Task.attempt (callback handle) - { } <- Task.await (close handle) + {} <- Task.await (close handle) Task.fromResult result diff --git a/examples/interactive/cli-platform/Task.roc b/examples/interactive/cli-platform/Task.roc index 9aee250a24..1abdfb040d 100644 --- a/examples/interactive/cli-platform/Task.roc +++ b/examples/interactive/cli-platform/Task.roc @@ -6,7 +6,7 @@ Task ok err : Effect.Effect (Result ok err) forever : Task val err -> Task * err forever = \task -> - looper = \{ } -> + looper = \{} -> task |> Effect.map \res -> diff --git a/examples/interactive/effects.roc b/examples/interactive/effects.roc index a81c87f1ea..ff4762704d 100644 --- a/examples/interactive/effects.roc +++ b/examples/interactive/effects.roc @@ -10,8 +10,8 @@ main = \line -> Effect.after (Effect.putLine "You entered: \(line)") - \{ } -> + \{} -> Effect.after (Effect.putLine "It is known") - \{ } -> + \{} -> Effect.always {} diff --git a/examples/interactive/tui.roc b/examples/interactive/tui.roc index 3f09cbfdf5..fdfdbf69ee 100644 --- a/examples/interactive/tui.roc +++ b/examples/interactive/tui.roc @@ -7,7 +7,7 @@ Model : Str main : Program Model main = { - init: \{ } -> "Hello World", + init: \{} -> "Hello World", update: \model, new -> Str.concat model new, view: \model -> Str.concat model "!", }