Fix edge case of formatting instability, b1186
authorSteve Hancock <perltidy@users.sourceforge.net>
Tue, 3 Aug 2021 01:57:04 +0000 (18:57 -0700)
committerSteve Hancock <perltidy@users.sourceforge.net>
Tue, 3 Aug 2021 01:57:04 +0000 (18:57 -0700)
dev-bin/run_convergence_tests.pl.data
lib/Perl/Tidy/Formatter.pm
local-docs/BugLog.pod

index 2fe5c8413862505c96f8b7a370dccbcf8f554911..f1461684a16c4fd610f5d83c269583acf85938ea 100644 (file)
@@ -6931,6 +6931,36 @@ ok(  (  Win32::GetFullPathName(
 --vertical-tightness=2
 --weld-nested-containers
 
+==> b1186.in <==
+# S1
+sub null_to_zzempty { }
+sub entab {
+
+          return
+            $table->{
+                    null_to_zzempty ( $row )
+            }->{ null_to_zzempty ( $col ) };
+}
+
+# S2
+sub null_to_zzemptY { }
+
+sub entaB {
+
+          return
+            $table->{ null_to_zzemptY (
+                                    $row ) }
+            ->{ null_to_zzemptY ( $col ) };
+}
+
+==> b1186.par <==
+--indent-columns=10
+--line-up-parentheses
+--maximum-line-length=44
+--paren-tightness=0
+--paren-vertical-tightness=2
+--space-function-paren
+
 ==> b120.in <==
 # Same as bug96
 # State 1
index d2d1bc52a37c24c3811767abb664664274edacc2..5c801e73b5b19c76547d1192e3be812fdcad86cf 100644 (file)
@@ -17140,10 +17140,12 @@ my %is_kwiZ;
 BEGIN {
 
     # Added 'w' to fix b1172
-    my @q = qw(k w i Z);
+    my @q = qw(k w i Z ->);
     @is_kwiZ{@q} = (1) x scalar(@q);
 }
 
+use constant DEBUG_FIND_START => 0;
+
 sub find_token_starting_list {
 
     # When testing to see if a block will fit on one line, some
@@ -17169,7 +17171,14 @@ sub find_token_starting_list {
         # a previous comma is a good break point
         # $i_opening_minus = $i_opening_paren;
     }
-    elsif ( $tokens_to_go[$i_opening_paren] eq '(' ) {
+
+    elsif (
+        $tokens_to_go[$i_opening_paren] eq '('
+
+        # non-parens added here to fix case b1186
+        || $is_kwiZ{$type_prev_nb}
+      )
+    {
         $i_opening_minus = $im1;
 
         # Walk back to improve length estimate...
@@ -17184,11 +17193,12 @@ sub find_token_starting_list {
         if ( $types_to_go[$i_opening_minus] eq 'b' ) { $i_opening_minus++ }
     }
 
-    # Handle non-parens
-    elsif ( $is_kwiZ{$type_prev_nb} ) { $i_opening_minus = $iprev_nb }
-
   RETURN:
 
+    DEBUG_FIND_START && print <<EOM;
+FIND_START: i=$i_opening_paren tok=$tokens_to_go[$i_opening_paren] => im=$i_opening_minus tok=$tokens_to_go[$i_opening_minus]
+EOM
+
     return $i_opening_minus;
 }
 
index dadd9848d10012cfd171fdcf388b1f361981f68d..cf543f87ed4cf389fb2ff5024d9cf7e35d9aaba6 100644 (file)
@@ -2,6 +2,15 @@
 
 =over 4
 
+=item B<Fix edge case of formatting instability, b1186>.
+
+Testing with random parameters produced a case of instability involving
+parameter -lp -pvt=n and a short maximum line length.
+
+This fixes case b1186.
+
+2 Aug 2021.
+
 =item B<Fix edge case of formatting instability, b1185>.
 
 Testing with random parameters produced a case of welding instability involving