From 8e7ca29a594c1347292e02b4b9f973434bdc909e Mon Sep 17 00:00:00 2001 From: TSUYUSATO Kitsune Date: Wed, 4 Apr 2018 00:20:04 +0900 Subject: [PATCH 1/2] Fix #5907 formatter bug --- spec/compiler/formatter/formatter_spec.cr | 1 + src/compiler/crystal/tools/formatter.cr | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/spec/compiler/formatter/formatter_spec.cr b/spec/compiler/formatter/formatter_spec.cr index e7b3170d89ad..d306f1d291eb 100644 --- a/spec/compiler/formatter/formatter_spec.cr +++ b/spec/compiler/formatter/formatter_spec.cr @@ -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" diff --git a/src/compiler/crystal/tools/formatter.cr b/src/compiler/crystal/tools/formatter.cr index 29af281c1070..e7bf374fd9d3 100644 --- a/src/compiler/crystal/tools/formatter.cr +++ b/src/compiler/crystal/tools/formatter.cr @@ -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 From 63acada1aa883e6a011234b123c38ae30148d575 Mon Sep 17 00:00:00 2001 From: TSUYUSATO Kitsune Date: Wed, 4 Apr 2018 00:20:14 +0900 Subject: [PATCH 2/2] Apply new formatter --- src/float/printer/grisu3.cr | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/float/printer/grisu3.cr b/src/float/printer/grisu3.cr index 297572f2212e..17734ed5c204 100644 --- a/src/float/printer/grisu3.cr +++ b/src/float/printer/grisu3.cr @@ -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