]> git.donarmstrong.com Git - perltidy.git/commitdiff
Slight change in weld length calculation
authorSteve Hancock <perltidy@users.sourceforge.net>
Fri, 9 Apr 2021 22:50:43 +0000 (15:50 -0700)
committerSteve Hancock <perltidy@users.sourceforge.net>
Fri, 9 Apr 2021 22:50:43 +0000 (15:50 -0700)
lib/Perl/Tidy/Formatter.pm
local-docs/BugLog.pod

index 5134f053a8a7b1dcf4c38c01a4b2f31ec02821a3..c7181dc888b870ec3835df0e6194445eb6728efe 100644 (file)
@@ -7039,6 +7039,9 @@ sub weld_nested_containers {
     my $rOpts_break_at_old_method_breakpoints =
       $rOpts->{'break-at-old-method-breakpoints'};
 
+    my $rOpts_ignore_side_comment_lengths =
+      $rOpts->{'ignore-side-comment-lengths'};
+
     # This array will hold the sequence numbers of the tokens to be welded.
     my @welds;
 
@@ -7072,6 +7075,34 @@ EOM
         return ($excess_length);
     };
 
+    my $excess_length_of_line = sub {
+        my ( $Kfirst, $Klast ) = @_;
+        my $length_before_Kfirst =
+          $Kfirst <= 0
+          ? 0
+          : $rLL->[ $Kfirst - 1 ]->[_CUMULATIVE_LENGTH_];
+        my $level    = $rLL->[$Kfirst]->[_LEVEL_];
+        my $ci_level = $rLL->[$Kfirst]->[_CI_LEVEL_];
+        my $indent   = $rOpts_indent_columns * $level +
+          $ci_level * $rOpts_continuation_indentation;
+        if ($rOpts_variable_maximum_line_length) {
+            $indent -= $level * $rOpts_indent_columns;
+        }
+
+        my $Kend = $Klast;
+        if (   $rOpts_ignore_side_comment_lengths
+            && $rLL->[$Klast]->[_TYPE_] eq '#' )
+        {
+            my $Kprev = $self->K_previous_nonblank($Klast);
+            if ( defined($Kprev) && $Kprev >= $Kfirst ) { $Kend = $Kprev }
+        }
+
+        my $length =
+          $rLL->[$Kend]->[_CUMULATIVE_LENGTH_] - $length_before_Kfirst;
+        my $excess_length = $indent + $length - $rOpts_maximum_line_length;
+        return ($excess_length);
+    };
+
     my $length_to_opening_seqno = sub {
         my ($seqno) = @_;
         my $KK      = $K_opening_container->{$seqno};
@@ -7248,8 +7279,8 @@ EOM
                 }
             }
 
-           # Revised -vmll treatment to fix cases b866 b1074 b1075 b1084 b1086
-           # b1087 b1088
+            # Revised -vmll treatment to fix cases b866 b1074 b1075 b1084 b1086
+            # b1087 b1088
             if ($rOpts_variable_maximum_line_length) {
                 $starting_indent -= $level * $rOpts_indent_columns;
             }
@@ -7288,9 +7319,10 @@ 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.
-            # For stability, we remove the length tolerance which has been added
+            # 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_to_K->($Klast) <= 0 )
+                && $excess_length_of_line->( $Kfirst, $Klast ) <= 0 )
             {
                 $is_one_line_weld = 1;
             }
@@ -21959,3 +21991,4 @@ sub wrapup {
 
 } ## end package Perl::Tidy::Formatter
 1;
+
index 5911c94d72c5deabd1971b93587c99f9f7de57e6..73e23eda6ef169241428b07c95cb082678ed995e 100644 (file)
@@ -3,6 +3,14 @@
 
 =over 4
 
+=item B<Slight change in weld length calculation>
+
+Random testing produced some cases of instability with some unusual input
+parameter combinations involving the -wn parameter.  This was fixed by revising
+a line length calculation.  This fixes cases b604 and b605.
+
+9 Apr 2021.
+
 =item B<Improve treatment of -vmll with -wn>
 
 Random testing showed a weakness in the treatment of the -vmll flag
@@ -10,7 +18,7 @@ in combination with the -wn flag.  This has been fixed.
 
 This fixes cases b866 b1074 b1075 b1084 b1086 b1087 b1088
 
-8 Apr 2021.
+8 Apr 2021, a6effa3.
 
 =item B<Merge weld rule 6 into rule 3>