From: Steve Hancock Date: Sun, 13 Jun 2021 01:28:12 +0000 (-0700) Subject: Fix edge cases of instability involving -wn -lp X-Git-Tag: 20210402.01~14 X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=125494b3db618c6ba655f4b698d443976a605025;p=perltidy.git Fix edge cases of instability involving -wn -lp --- diff --git a/lib/Perl/Tidy/Formatter.pm b/lib/Perl/Tidy/Formatter.pm index 81c8be3e..fb63dac4 100644 --- a/lib/Perl/Tidy/Formatter.pm +++ b/lib/Perl/Tidy/Formatter.pm @@ -7673,20 +7673,44 @@ EOM # FIX1: Changed 'excess_length_to_K' to 'excess_length_of_line' # to get exact lengths and fix b604 b605. if ( $iline_oo == $iline_oc ) { + + # All the tokens are on one line, now check their length my $excess = $self->excess_line_length_for_Krange( $Kfirst, $Klast ); if ( $excess <= 0 ) { + # All tokens are on one line and fit. This is a valid + # existing one-line weld except for some edge cases + # involving -lp: + # 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. # FIX3: for b1131: only use level difference in -lp mode. - my $level_diff = $rOpts_line_up_parentheses - && $outer_opening->[_LEVEL_] - $rLL->[$Kfirst]->[_LEVEL_]; - - if ( !$level_diff || $excess + $rOpts_indent_columns <= 0 ) + # FIX4: for b1141, b1142: reduce the tolerance for longer + # leading tokens + if ( $rOpts_line_up_parentheses + && $outer_opening->[_LEVEL_] - + $rLL->[$Kfirst]->[_LEVEL_] ) { + + # We only need a tolerance if the leading text before + # the first opening token is shorter than the + # indentation length. For simplicity we just use the + # length of the first token here. If necessary, we + # could be more exact in the future and find the + # total length up to the first opening token. + # See cases b1114, b1141, b1142. + my $tolx = max( 0, + $rOpts_indent_columns - + $rLL->[$Kfirst]->[_TOKEN_LENGTH_] ); + + if ( $excess + $tolx <= 0 ) { + $is_one_line_weld = 1; + } + } + else { $is_one_line_weld = 1; } } diff --git a/local-docs/BugLog.pod b/local-docs/BugLog.pod index c15750fe..d04776c8 100644 --- a/local-docs/BugLog.pod +++ b/local-docs/BugLog.pod @@ -2,6 +2,14 @@ =over 4 +=item B + +Random testing produced some cases of instability involving -wn -lp and some +unusual additional parameters. These were traced to a test for welding, +and were fixed by refining a certain tolerance. This fixes cases b1141, b1142. + +12 Jun 2021. + =item B This update removes an incorrect error messagge at the construct ')('. To illustrate, @@ -25,7 +33,7 @@ between a bareword [assumed to be a function] and a paren. This update is in Tokenizer.pm and fixes case c017. -6 Jun 2021. +6 Jun 2021, 6551d65. =item B @@ -41,7 +49,7 @@ perltidy will produce an error. y(1); } -6 Jun 2021. +6 Jun 2021, 32729fb. =item B