]> git.donarmstrong.com Git - perltidy.git/commitdiff
Fix edge case of formatting instability, b1184
authorSteve Hancock <perltidy@users.sourceforge.net>
Sat, 31 Jul 2021 00:25:08 +0000 (17:25 -0700)
committerSteve Hancock <perltidy@users.sourceforge.net>
Sat, 31 Jul 2021 00:25:08 +0000 (17:25 -0700)
dev-bin/run_convergence_tests.pl.data
lib/Perl/Tidy/Formatter.pm
local-docs/BugLog.pod

index 3da6364c675b416add1aafe47e91ffaf4888f404..2fe90564e30e920883af0cc734994f761b04ed87 100644 (file)
@@ -6855,6 +6855,31 @@ $orders= SearchOrders( {
 --maximum-line-length=55
 --weld-nested-containers
 
+==> b1184.in <==
+# S1
+ok(  (  Win32::GetFullPathName( substr
+        (   $cwd, 2 ) )
+     )[0],
+     "$dir\\"
+);
+
+# S2
+ok(  (  Win32::GetFullPathName(
+                   substr(
+                       $cwd, 2
+                   )
+        )
+     )[0],
+     "$dir\\"
+);
+
+==> b1184.par <==
+--extended-continuation-indentation
+--line-up-parentheses
+--maximum-line-length=30
+--weld-nested-containers
+--vertical-tightness=2
+
 ==> b120.in <==
 # Same as bug96
 # State 1
index bbdf577d7e2ca78972cf7eeeb9e8a877e7489de7..0eae6b4b269085b933f41b7b309477d330d27860 100644 (file)
@@ -7479,18 +7479,23 @@ sub is_excluded_weld {
     return $match;
 }
 
-# types needed for welding RULE 6
+# hashes to simplify welding logic
 my %type_ok_after_bareword;
-
 my %is_ternary;
+my %has_tight_paren;
 
 BEGIN {
 
+    # types needed for welding RULE 6
     my @q = qw# => -> { ( [ #;
     @type_ok_after_bareword{@q} = (1) x scalar(@q);
 
     @q = qw( ? : );
     @is_ternary{@q} = (1) x scalar(@q);
+
+    # these types do not 'like' to be separated from a following paren
+    @q = qw(w i q Q G C Z U);
+    @{has_tight_paren}{@q} = (1) x scalar(@q);
 }
 
 use constant DEBUG_WELD => 0;
@@ -8163,13 +8168,19 @@ EOM
         if ($do_not_weld_rule) {
 
             # After neglecting a pair, we start measuring from start of point io
-            my $starting_level    = $inner_opening->[_LEVEL_];
-            my $starting_ci_level = $inner_opening->[_CI_LEVEL_];
-            $starting_lentot =
-              $self->cumulative_length_before_K($Kinner_opening);
-            $maximum_text_length =
-              $maximum_text_length_at_level[$starting_level] -
-              $starting_ci_level * $rOpts_continuation_indentation;
+            # ... but not if previous type does not like to be separated from
+            # its container (fixes case b1184)
+            my $Kprev     = $self->K_previous_nonblank($Kinner_opening);
+            my $type_prev = defined($Kprev) ? $rLL->[$Kprev]->[_TYPE_] : 'w';
+            if ( !$has_tight_paren{$type_prev} ) {
+                my $starting_level    = $inner_opening->[_LEVEL_];
+                my $starting_ci_level = $inner_opening->[_CI_LEVEL_];
+                $starting_lentot =
+                  $self->cumulative_length_before_K($Kinner_opening);
+                $maximum_text_length =
+                  $maximum_text_length_at_level[$starting_level] -
+                  $starting_ci_level * $rOpts_continuation_indentation;
+            }
 
             if (DEBUG_WELD) {
                 $Msg .= "Not welding due to RULE $do_not_weld_rule\n";
index 74aea260062e9be353d27e42e10487f6047bd241..603f7ce8a5c278f0a437c016772f286b3b547669 100644 (file)
@@ -2,6 +2,15 @@
 
 =over 4
 
+=item B<Fix edge case of formatting instability, b1184>.
+
+Testing with random parameters produced a case of welding instability involving
+parameters -wn, -vt=n, -lp. This update fixes the problem.
+
+This fixes case b1184.
+
+28 Jul 2021.
+
 =item B<Fix edge case of formatting instability, b1182>.
 
 Testing with random parameters produced a case of welding instability involving