]> git.donarmstrong.com Git - perltidy.git/commitdiff
Fix rare problem with -lp -wn
authorSteve Hancock <perltidy@users.sourceforge.net>
Tue, 20 Apr 2021 01:58:14 +0000 (18:58 -0700)
committerSteve Hancock <perltidy@users.sourceforge.net>
Tue, 20 Apr 2021 01:58:14 +0000 (18:58 -0700)
lib/Perl/Tidy/Formatter.pm
local-docs/BugLog.pod

index 38aad9185039bfd499595b32ed186643296c0ef2..ff20d38447f615194790fa9f2444ad44fb59e5c3 100644 (file)
@@ -7420,12 +7420,23 @@ EOM
             # (1) the containers are all on one line, and
             # (2) the line does not exceed the allowable length, and
             # This flag is used to avoid creating blinkers.
-            # Changed 'excess_length_to_K' to 'excess_length_of_line'
+            # FIX1: Changed 'excess_length_to_K' to 'excess_length_of_line'
             # to get exact lengths and fix b604 b605.
-            if (   $iline_oo == $iline_oc
-                && $excess_length_of_line->( $Kfirst, $Klast ) <= 0 )
-            {
-                $is_one_line_weld = 1;
+            if ( $iline_oo == $iline_oc ) {
+                my $excess = $excess_length_of_line->( $Kfirst, $Klast );
+                if ( $excess <= 0 ) {
+
+                    # FIX2: Patch for b1114: add a tolerance of one level if
+                    # this line has an unbalanced start.  This helps prevent
+                    # blinkers in unusual cases for lines near the length limit
+                    # by making it more likely that RULE 2 will prevent a weld.
+                    my $level_diff =
+                      $outer_opening->[_LEVEL_] - $rLL->[$Kfirst]->[_LEVEL_];
+
+                    if ( !$level_diff || $excess + $rOpts_indent_columns <= 0 ) {
+                        $is_one_line_weld = 1;
+                    }
+                }
             }
 
             # DO-NOT-WELD RULE 1:
index e34785be38d2e5d1f95f4ee479ff7069120e2d19..37b058de640d189444e64438c55684a80d98c1d0 100644 (file)
@@ -2,6 +2,24 @@
 
 =over 4
 
+=item B<Fix rare problem with -lp -wn>
+
+Random testing produced case b1114 which gave unstable formatting with these 
+parameters
+
+    --noadd-whitespace
+    --indent-columns=8
+    --line-up-parentheses
+    --maximum-line-length=25
+    --weld-nested-containers
+
+and this snippet
+
+    is(length(pack("j", 0)),
+        $Config{ivsize});
+
+Fixed 19 Apr 2021.
+
 =item B<Fix issue git#63>
 
 The following lines produced an error message due to the side comment
@@ -9,8 +27,7 @@ The following lines produced an error message due to the side comment
     my $fragment = $parser->    #parse_html_string
       parse_balanced_chunk($I);
 
-This has been fixed.
-18 Apr 2021.
+Fixed 18 Apr 2021.
 
 =item B<Avoid welding at sort/map/grep paren calls>