From eeeaf093b46164d1e164b5c9e6ff6c2f0e4ef7bf Mon Sep 17 00:00:00 2001 From: Steve Hancock Date: Mon, 19 Apr 2021 18:58:14 -0700 Subject: [PATCH] Fix rare problem with -lp -wn --- lib/Perl/Tidy/Formatter.pm | 21 ++++++++++++++++----- local-docs/BugLog.pod | 21 +++++++++++++++++++-- 2 files changed, 35 insertions(+), 7 deletions(-) diff --git a/lib/Perl/Tidy/Formatter.pm b/lib/Perl/Tidy/Formatter.pm index 38aad918..ff20d384 100644 --- a/lib/Perl/Tidy/Formatter.pm +++ b/lib/Perl/Tidy/Formatter.pm @@ -7420,12 +7420,23 @@ EOM # (1) the containers are all on one line, and # (2) the line does not exceed the allowable length, and # This flag is used to avoid creating blinkers. - # Changed 'excess_length_to_K' to 'excess_length_of_line' + # FIX1: Changed 'excess_length_to_K' to 'excess_length_of_line' # to get exact lengths and fix b604 b605. - if ( $iline_oo == $iline_oc - && $excess_length_of_line->( $Kfirst, $Klast ) <= 0 ) - { - $is_one_line_weld = 1; + if ( $iline_oo == $iline_oc ) { + my $excess = $excess_length_of_line->( $Kfirst, $Klast ); + if ( $excess <= 0 ) { + + # FIX2: Patch for b1114: add a tolerance of one level if + # this line has an unbalanced start. This helps prevent + # blinkers in unusual cases for lines near the length limit + # by making it more likely that RULE 2 will prevent a weld. + my $level_diff = + $outer_opening->[_LEVEL_] - $rLL->[$Kfirst]->[_LEVEL_]; + + if ( !$level_diff || $excess + $rOpts_indent_columns <= 0 ) { + $is_one_line_weld = 1; + } + } } # DO-NOT-WELD RULE 1: diff --git a/local-docs/BugLog.pod b/local-docs/BugLog.pod index e34785be..37b058de 100644 --- a/local-docs/BugLog.pod +++ b/local-docs/BugLog.pod @@ -2,6 +2,24 @@ =over 4 +=item B + +Random testing produced case b1114 which gave unstable formatting with these +parameters + + --noadd-whitespace + --indent-columns=8 + --line-up-parentheses + --maximum-line-length=25 + --weld-nested-containers + +and this snippet + + is(length(pack("j", 0)), + $Config{ivsize}); + +Fixed 19 Apr 2021. + =item B The following lines produced an error message due to the side comment @@ -9,8 +27,7 @@ The following lines produced an error message due to the side comment my $fragment = $parser-> #parse_html_string parse_balanced_chunk($I); -This has been fixed. -18 Apr 2021. +Fixed 18 Apr 2021. =item B -- 2.39.5