]> git.donarmstrong.com Git - perltidy.git/commitdiff
Fix formatting instability issue b1194
authorSteve Hancock <perltidy@users.sourceforge.net>
Sat, 21 Aug 2021 20:18:32 +0000 (13:18 -0700)
committerSteve Hancock <perltidy@users.sourceforge.net>
Sat, 21 Aug 2021 20:18:32 +0000 (13:18 -0700)
dev-bin/run_convergence_tests.pl.data
lib/Perl/Tidy/Formatter.pm
local-docs/BugLog.pod

index e97ee52923051a726af9027f8fa5dc412077033f..1f63ba013237054590f48897b48fea8a86b1ea24 100644 (file)
@@ -7161,6 +7161,29 @@ print
 --maximum-line-length=49
 --square-bracket-vertical-tightness-closing=1
 
+==> b1194.in <==
+# S1
+          is(0+keys%mani,0+@files,"no duplicate files in MANIFEST")
+          or diag(
+                   join("\n  ","Duplicates:",grep$mani{$_}>1,
+                         keys%mani)
+          );
+# S2
+          is(0+keys%mani,0+@files,"no duplicate files in MANIFEST")
+          or
+          diag(join("\n  ","Duplicates:",grep$mani{$_}>1,keys%mani));
+
+
+==> b1194.par <==
+--noadd-whitespace
+--continuation-indentation=0
+--ignore-old-breakpoints
+--indent-columns=10
+--line-up-parentheses
+--maximum-line-length=70
+--paren-vertical-tightness=2
+--weld-nested-containers
+
 ==> b120.in <==
 # Same as bug96
 # State 1
index 3cc160dade032177f80e3acea1f707260ba1efa1..e388158f97842288a39605c7771a520d2fdd1771 100644 (file)
@@ -6731,8 +6731,15 @@ sub parent_seqno_by_K {
     while ( defined($Ktest) ) {
         my $type = $rLL->[$Ktest]->[_TYPE_];
 
+        # if next container token is opening, we want its parent container
+        if ( $is_opening_type{$type} ) {
+            my $type_sequence = $rLL->[$Ktest]->[_TYPE_SEQUENCE_];
+            $parent_seqno = $self->[_rparent_of_seqno_]->{$type_sequence};
+            last;
+        }
+
         # if next container token is closing, it is the parent seqno
-        if ( $is_closing_type{$type} ) {
+        elsif ( $is_closing_type{$type} ) {
             my $type_sequence = $rLL->[$Ktest]->[_TYPE_SEQUENCE_];
             if ( $Ktest > $KK ) {
                 $parent_seqno = $type_sequence;
@@ -6743,13 +6750,6 @@ sub parent_seqno_by_K {
             last;
         }
 
-        # if next container token is opening, we want its parent container
-        elsif ( $is_opening_type{$type} ) {
-            my $type_sequence = $rLL->[$Ktest]->[_TYPE_SEQUENCE_];
-            $parent_seqno = $self->[_rparent_of_seqno_]->{$type_sequence};
-            last;
-        }
-
         # not a container - must be ternary - keep going
         $Ktest = $rLL->[$Ktest]->[_KNEXT_SEQ_ITEM_];
     }
@@ -8064,19 +8064,6 @@ EOM
                     else {
                         $is_one_line_weld = 1;
                     }
-
-                    # If an apparent one-line weld might have been created by
-                    # -vt and -lp, then do not mark as a one-line weld.
-                    # This condition added to fix b1183.
-                    # Added block type test to fix b1191
-                    if (   $is_one_line_weld
-                        && $rOpts_line_up_parentheses
-                        && $opening_vertical_tightness{$token_oo}
-                        && !$rblock_type_of_seqno->{$inner_seqno}
-                        && !$ris_excluded_lp_container->{$outer_seqno} )
-                    {
-                        $is_one_line_weld = 0;
-                    }
                 }
             }
 
@@ -22103,6 +22090,7 @@ sub set_vertical_tightness_flags {
       if ($rOpts_freeze_whitespace);
 
     my $rwant_container_open = $self->[_rwant_container_open_];
+    my $rK_weld_left         = $self->[_rK_weld_left_];
 
     # Uses these global parameters:
     #   $rOpts_block_brace_tightness
@@ -22149,6 +22137,14 @@ sub set_vertical_tightness_flags {
             # requested
             my $ovt       = $opening_vertical_tightness{$token_end};
             my $iend_next = $ri_last->[ $n + 1 ];
+
+            # Turn off the -vt flag if the next line ends in a weld.
+            # This avoids an instability with one-line welds (fixes b1183).
+            my $type_end_next = $types_to_go[$iend_next];
+            $ovt = 0
+              if ( $rK_weld_left->{ $K_to_go[$iend_next] }
+                && $is_closing_type{$type_end_next} );
+
             unless (
                 $ovt < 2
                 && ( $nesting_depth_to_go[ $iend_next + 1 ] !=
index 994d960726e8d8ede7c387b5944cbbf2b378d1ad..d7d8a7df2a9ddf8db34b682642c9f5276ec9a25c 100644 (file)
@@ -2,6 +2,16 @@
 
 =over 4
 
+=item B<Fix formatting instability issue b1194>
+
+Testing with random parameters produced a case of unstable formatting
+which is fixed with this update.
+
+This fixes case b1194, and at the same time it simplifies the logic
+which handles issues b1183 and b1191.
+
+21 Aug 2021.
+
 =item B<Fix some problems involving tabs characters, case c062>
 
 This update fixes some problems found in random testing with tab characters.