From 620003477cf4d5aa6a57e771557d223012690f01 Mon Sep 17 00:00:00 2001 From: Steve Hancock Date: Thu, 18 Mar 2021 17:59:14 -0700 Subject: [PATCH] Fix rare problem with combination -lp -wn -naws --- lib/Perl/Tidy/Formatter.pm | 35 +++++++++++++++++++++++++---------- local-docs/BugLog.pod | 14 +++++++++++++- 2 files changed, 38 insertions(+), 11 deletions(-) diff --git a/lib/Perl/Tidy/Formatter.pm b/lib/Perl/Tidy/Formatter.pm index 021b6f4e..d1cda185 100644 --- a/lib/Perl/Tidy/Formatter.pm +++ b/lib/Perl/Tidy/Formatter.pm @@ -7026,17 +7026,28 @@ EOM # The combination -wn -lp -dws -naws does not work well and can # cause blinkers. See case b1020. It will probably only occur # in stress testing. For this situation we will only weld if we - # start at a 'good' location. + # start at a 'good' location. Added 'if' to fix case b1032. if ( $ci_level && $rOpts_line_up_parentheses && $rOpts_delete_old_whitespace && !$rOpts_add_whitespace ) { - my $type_first = $rLL->[$Kfirst]->[_TYPE_]; - my $type_prev = $rLL->[$Kprev]->[_TYPE_]; - unless ( $type_prev =~ /^[=\,\.\{\[\(\L]/ - || $type_first =~ /^[=\,\.\{\[\(\L]/ ) + my $type_first = $rLL->[$Kfirst]->[_TYPE_]; + my $type_prev = $rLL->[$Kprev]->[_TYPE_]; + my $token_first = $rLL->[$Kfirst]->[_TOKEN_]; + unless ( + $type_prev =~ /^[=\,\.\{\[\(\L]/ + || $type_first =~ /^[=\,\.\{\[\(\L]/ + || $type_first eq '||' + || ( $type_first eq 'k' && $token_first eq 'if' + || $token_first eq 'or' ) + ) { + if (DEBUG_WELD) { + $Msg .= +"Skipping weld: poor break with -lp and ci at type_first='$type_first' type_prev='$type_prev'\n"; + print $Msg; + } next; } } @@ -8215,6 +8226,7 @@ sub extended_ci { my $rLL = $self->[_rLL_]; return unless ( defined($rLL) && @{$rLL} ); + my $ris_list_by_seqno = $self->[_ris_list_by_seqno_]; my $ris_seqno_controlling_ci = $self->[_ris_seqno_controlling_ci_]; my $rseqno_controlling_my_ci = $self->[_rseqno_controlling_my_ci_]; my $rlines = $self->[_rlines_]; @@ -8244,18 +8256,21 @@ sub extended_ci { # Fix all tokens up to the next sequence item if we are changing CI if ($seqno_top) { - my $space = $available_space{$seqno_top}; - my $length = $rLL->[$KLAST]->[_CUMULATIVE_LENGTH_]; - my $count = 0; + my $is_list = $ris_list_by_seqno->{$seqno_top}; + my $space = $available_space{$seqno_top}; + my $length = $rLL->[$KLAST]->[_CUMULATIVE_LENGTH_]; + my $count = 0; for ( my $Kt = $KLAST + 1 ; $Kt < $KNEXT ; $Kt++ ) { - # but do not include tokens which might exceed the line length + # But do not include tokens which might exceed the line length + # and are not in a list. # ... This fixes case b1031 my $length_before = $length; $length = $rLL->[$Kt]->[_CUMULATIVE_LENGTH_]; if ( !$rLL->[$Kt]->[_CI_LEVEL_] - && ( $length - $length_before < $space + && ( $is_list + || $length - $length_before < $space || $rLL->[$Kt]->[_TYPE_] eq '#' ) ) { diff --git a/local-docs/BugLog.pod b/local-docs/BugLog.pod index 4720c406..dc134cf1 100644 --- a/local-docs/BugLog.pod +++ b/local-docs/BugLog.pod @@ -2,6 +2,18 @@ =over 4 +=item B + +This update fixes case b1032 by includeing lines starting with 'if', 'or', and +|| among the stable breakpoints for welding when -lp -naws flags are also +set. + +This update also modifies update 7a6be43 of 16 Mar 2021 to exclude list items +when checking token lengths. This reduces changes to existing formatting +while still fixing the problem in case b1031. + +18 Mar 2021. + =item B Testing produced a blinking state involving a -bbx=2 flag with an unusual @@ -9,7 +21,7 @@ combination of other parameters. The problem was traced to the definition of a list containg another list being too restrictive. This update fixes case 1024. -17 Mar 2021. +17 Mar 2021, 7f5da0a. =item B -- 2.39.5