]> git.donarmstrong.com Git - perltidy.git/commitdiff
fix b1409
authorSteve Hancock <perltidy@users.sourceforge.net>
Sat, 29 Oct 2022 15:06:38 +0000 (08:06 -0700)
committerSteve Hancock <perltidy@users.sourceforge.net>
Sat, 29 Oct 2022 15:06:38 +0000 (08:06 -0700)
dev-bin/run_convergence_tests.pl.data
lib/Perl/Tidy/Formatter.pm

index 24571afb923b02ea923521b6d469c892009ef8ef..691bf301c15be193a032190e7b6dee33c1917cfe 100644 (file)
@@ -10656,6 +10656,24 @@ my %MyTokens= (
 --maximum-line-length=47
 --want-trailing-commas='i'
 
+==> b1409.in <==
+      local(
+            %cached_env_img,%id_map,
+            %symbolic_labels,%latex_labels
+      )if($FIXEDDIR&&$NO_SUBDIR);
+
+      local(%cached_env_img,%id_map,%symbolic_labels,
+            %latex_labels,)
+        if($FIXEDDIR&&$NO_SUBDIR);
+
+==> b1409.par <==
+--add-trailing-commas
+--delete-trailing-commas
+--want-trailing-commas='b'
+--indent-columns=6
+--maximum-line-length=66
+--noadd-whitespace
+
 ==> b146.in <==
 # State 1
 
index e07c6e8097d16160770ed2d13aba31197ab6a902..b7381312f7163eee076c04edd69bc796e3426d11 100644 (file)
@@ -7845,8 +7845,19 @@ sub delete_trailing_comma {
       $self->match_trailing_comma_rule( $KK, $Kfirst, $Kp,
         $trailing_comma_rule, 0 );
 
-    # If not, delete it
+    # Patch: the --noadd-whitespace flag can cause instability in complex
+    # structures. In this case do not delete the comma. Fixes b1409.
+    if ( !$match && !$rOpts_add_whitespace ) {
+        my $Kn = $self->K_next_nonblank($KK);
+        if ( defined($Kn) ) {
+            my $type_n = $rLL->[$Kn]->[_TYPE_];
+            if ( $type_n ne ';' && $type_n ne '#' ) { return }
+        }
+    }
+
+    # If no match, delete it
     if ( !$match ) {
+
         return $self->unstore_last_nonblank_token(',');
     }
     return;