]> git.donarmstrong.com Git - perltidy.git/commitdiff
Fix rare convergence problem with -wn
authorSteve Hancock <perltidy@users.sourceforge.net>
Sat, 3 Apr 2021 14:38:02 +0000 (07:38 -0700)
committerSteve Hancock <perltidy@users.sourceforge.net>
Sat, 3 Apr 2021 14:38:02 +0000 (07:38 -0700)
bin/perltidy
lib/Perl/Tidy/Formatter.pm
local-docs/BugLog.pod
t/snippets/expect/wn6.wn
t/snippets/packing_list.txt
t/snippets12.t

index f08820c61f1d4b253209fa11cc0b88db30c0804e..990f46d85ce8833f60f764810d7a4004f3cf5523 100755 (executable)
@@ -4127,6 +4127,10 @@ Space before and after the curly braces is optional.
 
 For a specific example, the following line
 
+        oneliner { --maximum-line-length=0 --noadd-newlines }
+
+or equivalently with abbreviations
+
        oneliner { -l=0 -nanl }
 
 could be placed in a F<.perltidyrc> file to temporarily override the maximum
index 32e099119da7450a312c94fc6f10cef961c67f6c..1f09c210f791c9f94bafceb0d6d88d0efb2100ba 100644 (file)
@@ -7035,6 +7035,7 @@ sub weld_nested_containers {
     # Variables needed for estimating line lengths
     my $starting_indent;
     my $starting_lentot;
+    my $starting_level;
     my $iline_outer_opening   = -1;
     my $weld_count_this_start = 0;
 
@@ -7050,7 +7051,17 @@ sub weld_nested_containers {
 
         # Add a tolerance for welds over multiple lines to avoid blinkers
         my $iline_K = $rLL->[$K]->[_LINE_INDEX_];
-        my $tol     = ( $iline_K > $iline_outer_opening ) ? $multiline_tol : 0;
+        my $level_K = $rLL->[$K]->[_LEVEL_];
+        my $tol     = 0;
+        if (
+            $iline_K > $iline_outer_opening
+
+            # fix for cases b1041 b1055:
+            || $level_K > $starting_level
+          )
+        {
+            $tol = $multiline_tol;
+        }
 
         my $excess_length =
           $starting_indent + $length + $tol - $rOpts_maximum_line_length;
@@ -7207,11 +7218,11 @@ EOM
               $Kref <= 0 ? 0 : $rLL->[ $Kref - 1 ]->[_CUMULATIVE_LENGTH_];
 
             $starting_indent = 0;
-            my $level    = $rLL->[$Kref]->[_LEVEL_];
+            $starting_level  = $rLL->[$Kref]->[_LEVEL_];
             my $ci_level = $rLL->[$Kref]->[_CI_LEVEL_];
             if ( !$rOpts_variable_maximum_line_length ) {
 
-                $starting_indent = $rOpts_indent_columns * $level +
+                $starting_indent = $rOpts_indent_columns * $starting_level +
                   $ci_level * $rOpts_continuation_indentation;
             }
 
@@ -7300,7 +7311,7 @@ EOM
                     }
                 }
             }
-        }
+        } ## end starting new weld sequence
 
         # DO-NOT-WELD RULE 2:
         # Do not weld an opening paren to an inner one line brace block
@@ -7443,9 +7454,9 @@ EOM
             $starting_lentot =
               $self->cumulative_length_before_K($Kinner_opening);
             $starting_indent = 0;
+            $starting_level  = $inner_opening->[_LEVEL_];
             if ( !$rOpts_variable_maximum_line_length ) {
-                my $level = $inner_opening->[_LEVEL_];
-                $starting_indent = $rOpts_indent_columns * $level;
+                $starting_indent = $rOpts_indent_columns * $starting_level;
             }
 
             if (DEBUG_WELD) {
index 1cdcb7597b122f6a6a57c0f4e4362937978113ae..3f46c9b6334be4d68fe73e2650fc93c0ecd30ecd 100644 (file)
@@ -3,6 +3,16 @@
 
 =over 4
 
+=item B<Fix rare convergence problem with -wn>
+
+Random testing produced some cases in which unusual parameter combinations
+caused lack of convergence for the -wn flag.  The problem was fixed by
+adjusting a tolerance in the line length calculation.
+
+This fixes cases b1041 b1055.
+
+2 Apr 2021.
+
 =item B<Avoid conflict of -bli and -xci>
 
 Random testing produced a case with the combination -bli and -xci which did not
index b037744b6cc98c93729233dc27f9718faacbdeb4..93b8037809b2abff7821c6a4699f3d4156fd7d9d 100644 (file)
@@ -5,9 +5,9 @@
                 PDL::Graphics::TriD::Scale->new( $sx, $sy, $sz ) );
 
             # but weld this more complex statement
-            my $compass = uc( opposite_direction( line_to_canvas_direction(
-                @{ $coords[0] }, @{ $coords[1] }
-            ) ) );
+            my $compass = uc( opposite_direction(
+                line_to_canvas_direction( @{ $coords[0] }, @{ $coords[1] } )
+            ) );
 
             # OLD: do not weld to a one-line block because the function could
             # get separated from its opening paren.
index 6bcd97e3475ec952814980e0013465e3ec132071..8eabb077381e4afe854788bb6782a5d701a08fb7 100644 (file)
 ../snippets24.t        fpva.fpva2
 ../snippets24.t        lpxl.def
 ../snippets24.t        lpxl.lpxl1
-../snippets24.t        lpxl.lpxl2
 ../snippets24.t        lpxl.lpxl3
 ../snippets24.t        lpxl.lpxl4
 ../snippets24.t        lpxl.lpxl5
index 76958dace1ae69c94f27d4cbe445e392e86c8469..a9798f4d856f82ccc8ed42cb04c70f1f5e7f8d40 100644 (file)
@@ -544,9 +544,9 @@ use_all_ok( qw{
                 PDL::Graphics::TriD::Scale->new( $sx, $sy, $sz ) );
 
             # but weld this more complex statement
-            my $compass = uc( opposite_direction( line_to_canvas_direction(
-                @{ $coords[0] }, @{ $coords[1] }
-            ) ) );
+            my $compass = uc( opposite_direction(
+                line_to_canvas_direction( @{ $coords[0] }, @{ $coords[1] } )
+            ) );
 
             # OLD: do not weld to a one-line block because the function could
             # get separated from its opening paren.