]> git.donarmstrong.com Git - perltidy.git/commitdiff
Fix edge cases of instability involving -wn -lp
authorSteve Hancock <perltidy@users.sourceforge.net>
Sun, 13 Jun 2021 01:28:12 +0000 (18:28 -0700)
committerSteve Hancock <perltidy@users.sourceforge.net>
Sun, 13 Jun 2021 01:28:12 +0000 (18:28 -0700)
lib/Perl/Tidy/Formatter.pm
local-docs/BugLog.pod

index 81c8be3e471ac7a5e912e34a4b40174db0a38e5c..fb63dac48c09be4f6298d69874d4168994016c90 100644 (file)
@@ -7673,20 +7673,44 @@ EOM
             # FIX1: Changed 'excess_length_to_K' to 'excess_length_of_line'
             # to get exact lengths and fix b604 b605.
             if ( $iline_oo == $iline_oc ) {
+
+                # All the tokens are on one line, now check their length
                 my $excess =
                   $self->excess_line_length_for_Krange( $Kfirst, $Klast );
                 if ( $excess <= 0 ) {
 
+                    # All tokens are on one line and fit. This is a valid
+                    # existing one-line weld except for some edge cases
+                    # involving -lp:
+
                     # 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.
                     # FIX3: for b1131: only use level difference in -lp mode.
-                    my $level_diff = $rOpts_line_up_parentheses
-                      && $outer_opening->[_LEVEL_] - $rLL->[$Kfirst]->[_LEVEL_];
-
-                    if ( !$level_diff || $excess + $rOpts_indent_columns <= 0 )
+                    # FIX4: for b1141, b1142: reduce the tolerance for longer
+                    # leading tokens
+                    if (   $rOpts_line_up_parentheses
+                        && $outer_opening->[_LEVEL_] -
+                        $rLL->[$Kfirst]->[_LEVEL_] )
                     {
+
+                        # We only need a tolerance if the leading text before
+                        # the first opening token is shorter than the
+                        # indentation length.  For simplicity we just use the
+                        # length of the first token here.  If necessary, we
+                        # could be more exact in the future and find the
+                        # total length up to the first opening token.
+                        # See cases b1114, b1141, b1142.
+                        my $tolx = max( 0,
+                            $rOpts_indent_columns -
+                              $rLL->[$Kfirst]->[_TOKEN_LENGTH_] );
+
+                        if ( $excess + $tolx <= 0 ) {
+                            $is_one_line_weld = 1;
+                        }
+                    }
+                    else {
                         $is_one_line_weld = 1;
                     }
                 }
index c15750fe7b1854251369326fdc708fd84f5cb2ef..d04776c8a6dc68cf24e2344ea2a0dd908ef0d518 100644 (file)
@@ -2,6 +2,14 @@
 
 =over 4
 
+=item B<Fix edge cases of instability involving -wn -lp>
+
+Random testing produced some cases of instability involving -wn -lp and some
+unusual additional parameters.  These were traced to a test for welding,
+and were fixed by refining a certain tolerance.  This fixes cases b1141, b1142.
+
+12 Jun 2021.
+
 =item B<Remove incorrect warning at repeated function paren call>
 
 This update removes an incorrect error messagge at the construct ')('.  To illustrate,
@@ -25,7 +33,7 @@ between a bareword [assumed to be a function] and a paren.
 
 This update is in Tokenizer.pm and fixes case c017.
 
-6 Jun 2021.
+6 Jun 2021, 6551d65.
 
 =item B<Add warning when lexical sub names match some builtins>
 
@@ -41,7 +49,7 @@ perltidy will produce an error.
       y(1);
     }
 
-6 Jun 2021.
+6 Jun 2021, 32729fb.
 
 =item B<Minor cleanups>