From 68f619af9e1c621e4a0db584afa600872669607a Mon Sep 17 00:00:00 2001 From: Steve Hancock Date: Sun, 9 May 2021 16:29:24 -0700 Subject: [PATCH] Fix some edge welding cases --- lib/Perl/Tidy/Formatter.pm | 20 +++++++++++++++++--- local-docs/BugLog.pod | 12 ++++++++++-- 2 files changed, 27 insertions(+), 5 deletions(-) diff --git a/lib/Perl/Tidy/Formatter.pm b/lib/Perl/Tidy/Formatter.pm index 00d3338e..da7359c1 100644 --- a/lib/Perl/Tidy/Formatter.pm +++ b/lib/Perl/Tidy/Formatter.pm @@ -7230,6 +7230,15 @@ sub setup_new_weld_measurements { { if ( substr( $type_prev, 0, 1 ) eq '=' ) { $Kref = $Kprev; + + # Backup to the start of the previous line if it ends in => + # Fixes case b1112. + if ( $type_prev eq '=>' ) { + my $iline_prev = $rLL->[$Kprev]->[_LINE_INDEX_]; + my $rK_range = $rlines->[$iline_prev]->{_rK_range}; + my ( $Kfirst, $Klast ) = @{$rK_range}; + $Kref = $Kfirst; + } } } } @@ -7279,16 +7288,21 @@ sub setup_new_weld_measurements { # 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. Added 'if' to fix case b1032. + # Require blank before certain previous characters to fix b1111. if ( $starting_ci && $rOpts_line_up_parentheses && $rOpts_delete_old_whitespace - && !$rOpts_add_whitespace ) + && !$rOpts_add_whitespace + && defined($Kprev) ) { my $type_first = $rLL->[$Kfirst]->[_TYPE_]; - my $type_prev = $rLL->[$Kprev]->[_TYPE_]; my $token_first = $rLL->[$Kfirst]->[_TOKEN_]; + my $type_prev = $rLL->[$Kprev]->[_TYPE_]; + my $type_pp = 'b'; + if ( $Kprev >= 0 ) { $type_pp = $rLL->[ $Kprev - 1 ]->[_TYPE_] } unless ( - $type_prev =~ /^[=\,\.\{\[\(\L]/ + $type_prev =~ /^[\,\.]/ + || $type_prev =~ /^[=\{\[\(\L]/ && $type_pp eq 'b' || $type_first =~ /^[=\,\.\{\[\(\L]/ || $type_first eq '||' || ( $type_first eq 'k' && $token_first eq 'if' diff --git a/local-docs/BugLog.pod b/local-docs/BugLog.pod index ee9191b7..d147f3d8 100644 --- a/local-docs/BugLog.pod +++ b/local-docs/BugLog.pod @@ -2,6 +2,14 @@ =over 4 +=item B + +Some adjustments in welding coding was made to maintain stability for some +unusual parameter combinations. + +This fixes cases b1111 b1112. +9 May 2021. + =item B The tolerance for welding qw quotes has been update to be the same as used @@ -40,7 +48,7 @@ It has no effect if -lp is not used. CroakWinError )]); -9 May 2021. +9 May 2021, ad8870b. =item B @@ -49,7 +57,7 @@ to the formatter if the type of a brace following an unknown bareword had to be guessed. The formatter has more information and can fix the problem. This fixes case b1128. -8 May 2021. +8 May 2021, b3eaf23. =item B -- 2.39.5