]> git.donarmstrong.com Git - perltidy.git/commitdiff
Fix some edge welding cases
authorSteve Hancock <perltidy@users.sourceforge.net>
Sun, 9 May 2021 23:29:24 +0000 (16:29 -0700)
committerSteve Hancock <perltidy@users.sourceforge.net>
Sun, 9 May 2021 23:29:24 +0000 (16:29 -0700)
lib/Perl/Tidy/Formatter.pm
local-docs/BugLog.pod

index 00d3338e68582f715e58301f19eade380e881dc8..da7359c10dbb42f7aff5647d6339d4d633ad81ca 100644 (file)
@@ -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'
index ee9191b775652acf51757dfefa2c2e4a3fe3ab6f..d147f3d8bb96e04ad68a48c9c6aeec603a78782d 100644 (file)
@@ -2,6 +2,14 @@
 
 =over 4
 
+=item B<Fix some edge welding cases>
+
+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<Improve tolerance for welding qw quotes>
 
 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<Correct brace types mismarked by tokenizer, update>
 
@@ -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<Added warning when -ci has to be reduced; ref rt #136415>