From a4609acec2e8af01e7ab31242cda4502916802b5 Mon Sep 17 00:00:00 2001 From: Steve Hancock Date: Tue, 9 Feb 2021 18:03:17 -0800 Subject: [PATCH] Modify tolerance in testing for welds --- lib/Perl/Tidy/Formatter.pm | 13 +++++++++---- local-docs/BugLog.pod | 13 ++++++++++++- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/lib/Perl/Tidy/Formatter.pm b/lib/Perl/Tidy/Formatter.pm index 05b2e2d1..43ab58db 100644 --- a/lib/Perl/Tidy/Formatter.pm +++ b/lib/Perl/Tidy/Formatter.pm @@ -6857,6 +6857,8 @@ sub weld_nested_containers { my $iline_oc = $outer_closing->[_LINE_INDEX_]; + my $is_old_weld = ( $iline_oo == $iline_io && $iline_ic == $iline_oc ); + if ( !$touch_previous_pair ) { # If this pair is not adjacent to the previous pair (skipped or @@ -6962,8 +6964,11 @@ sub weld_nested_containers { } # DO-NOT-WELD RULE 3: - # Do not weld if this makes our line too long - $do_not_weld ||= $excess_length_to_K->($Kinner_opening) >= 0; + # Do not weld if this makes our line too long. + # Use a tolerance which depends on if the old tokens were welded + # (fixes cases b746 b748 b749 b750 b752 b753 b754 b755 b756 b758 b759) + $do_not_weld ||= $excess_length_to_K->($Kinner_opening) >= + ( $is_old_weld ? $length_tol : 0 ); # DO-NOT-WELD RULE 4; implemented for git#10: # Do not weld an opening -ce brace if the next container is on a single @@ -14356,8 +14361,8 @@ sub set_continuation_breaks { if ( $old_breakpoint_to_go[$i_first_comma] && $level_comma == $levels_to_go[0] ) { - my $ibreak = -1; - my $obp_count = 0; + my $ibreak = -1; + my $obp_count = 0; for ( my $ii = $i_first_comma - 1 ; $ii >= 0 ; $ii -= 1 ) { if ( $old_breakpoint_to_go[$ii] ) { $obp_count++; diff --git a/local-docs/BugLog.pod b/local-docs/BugLog.pod index ea3cb1a6..d0f27066 100644 --- a/local-docs/BugLog.pod +++ b/local-docs/BugLog.pod @@ -2,6 +2,17 @@ =over 4 +=item B + +Random testing with unusual parameters produced some blinking weld states which +were fixed by modifying a tolerance used in a line length test. The following +cases were fixed with this update: + +b746 b748 b749 b750 b752 b753 b754 b755 b756 b758 b759 b771 b772 b773 b774 +b782 b783 b784 b785 b786 + +9 Feb 2021. + =item B Random testing produced some blinking cases resulting from the treatment of old @@ -11,7 +22,7 @@ were fixed with this update: b064 b065 b068 b210 b747 This change has no effect on scripts with normal parameter values. -9 Feb 2021. +9 Feb 2021, 5c23661. =item B -- 2.39.5