Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #5907 formatter bug #5909

Merged
merged 2 commits into from
Apr 3, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions spec/compiler/formatter/formatter_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,7 @@ describe Crystal::Formatter do
assert_format "1 && 2", "1 && 2"
assert_format "1 &&\n2", "1 &&\n 2"
assert_format "1 &&\n2 &&\n3", "1 &&\n 2 &&\n 3"
assert_format "1 && # foo\n 2 &&\n 3"
assert_format "if 0\n1 &&\n2 &&\n3\nend", "if 0\n 1 &&\n 2 &&\n 3\nend"
assert_format "if 1 &&\n2 &&\n3\n4\nend", "if 1 &&\n 2 &&\n 3\n 4\nend"
assert_format "if 1 &&\n (2 || 3)\n 1\nelse\n 2\nend"
Expand Down
4 changes: 2 additions & 2 deletions src/compiler/crystal/tools/formatter.cr
Original file line number Diff line number Diff line change
Expand Up @@ -2946,8 +2946,8 @@ module Crystal
end

write_token " ", token
skip_space
if @token.type == :NEWLINE
found_comment = skip_space
if found_comment || @token.type == :NEWLINE
if @inside_call_or_assign == 0
next_indent = @inside_cond == 0 ? @indent + 2 : @indent
else
Expand Down
8 changes: 4 additions & 4 deletions src/float/printer/grisu3.cr
Original file line number Diff line number Diff line change
Expand Up @@ -126,10 +126,10 @@ module Float::Printer::Grisu3
# We need to do the following tests in this order to avoid over- and
# underflows.
while (
rest < small_distance && # Negated condition 1
unsafe_interval - rest >= ten_kappa && # Negated condition 2
(rest + ten_kappa < small_distance || # buffer{-1} > w_high
small_distance - rest >= rest + ten_kappa - small_distance)
rest < small_distance && # Negated condition 1
unsafe_interval - rest >= ten_kappa && # Negated condition 2
(rest + ten_kappa < small_distance || # buffer{-1} > w_high
small_distance - rest >= rest + ten_kappa - small_distance)
)
buffer[length - 1] -= 1
rest += ten_kappa
Expand Down