Skip to content

Commit e30f8df

Browse files
committed
Do not loop when invalid block is given to formatter, closes #12922
1 parent 2fe5b77 commit e30f8df

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

lib/elixir/lib/code/formatter.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -431,7 +431,7 @@ defmodule Code.Formatter do
431431
{color("nil", nil, state.inspect_opts), state}
432432
end
433433

434-
defp quoted_to_algebra({:__block__, meta, _} = block, _context, state) do
434+
defp quoted_to_algebra({:__block__, meta, args} = block, _context, state) when is_list(args) do
435435
{block, state} = block_to_algebra(block, line(meta), closing_line(meta), state)
436436
{surround("(", block, ")"), state}
437437
end

lib/elixir/test/elixir/code_normalizer/quoted_ast_test.exs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,11 @@ defmodule Code.Normalizer.QuotedASTTest do
226226
assert quoted_to_string(quoted) <> "\n" == expected
227227
end
228228

229+
test "invalid block" do
230+
assert quoted_to_string({:__block__, [], {:bar, [], []}}) ==
231+
"{:__block__, [], {:bar, [], []}}"
232+
end
233+
229234
test "not in" do
230235
assert quoted_to_string(quote(do: false not in [])) == "false not in []"
231236
end

0 commit comments

Comments
 (0)