Skip to content

Commit ff2ea69

Browse files
sabiwarajosevalim
authored andcommitted
Fix Macro.to_string/1 for large negative integers (#12326)
1 parent 2146bb4 commit ff2ea69

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

lib/elixir/lib/code/formatter.ex

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1583,6 +1583,10 @@ defmodule Code.Formatter do
15831583
insert_underscores(int_part) <> "." <> decimal_part
15841584
end
15851585

1586+
defp insert_underscores("-" <> digits) do
1587+
"-" <> insert_underscores(digits)
1588+
end
1589+
15861590
defp insert_underscores(digits) do
15871591
cond do
15881592
digits =~ "_" ->

lib/elixir/test/elixir/macro_test.exs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -429,6 +429,16 @@ defmodule MacroTest do
429429
test "converts quoted to string" do
430430
assert Macro.to_string(quote do: hello(world)) == "hello(world)"
431431
end
432+
433+
test "large number literals" do
434+
# with quote
435+
assert Macro.to_string(quote do: 576_460_752_303_423_455) == "576_460_752_303_423_455"
436+
assert Macro.to_string(quote do: -576_460_752_303_423_455) == "-576_460_752_303_423_455"
437+
438+
# without quote
439+
assert Macro.to_string(576_460_752_303_423_455) == "576_460_752_303_423_455"
440+
assert Macro.to_string(-576_460_752_303_423_455) == "-576_460_752_303_423_455"
441+
end
432442
end
433443

434444
describe "to_string/2" do

0 commit comments

Comments
 (0)