Skip to content

Commit

Permalink
Fix #5907 formatter bug (#5909)
Browse files Browse the repository at this point in the history
* Fix #5907 formatter bug

* Apply new formatter
  • Loading branch information
makenowjust authored and RX14 committed Apr 3, 2018
1 parent 5056859 commit ec423eb
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
1 change: 1 addition & 0 deletions spec/compiler/formatter/formatter_spec.cr
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
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
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

0 comments on commit ec423eb

Please sign in to comment.