From a25cfaa1afc2174ca27ddf930fa141b82b877ff1 Mon Sep 17 00:00:00 2001 From: Steve Hancock Date: Fri, 9 Apr 2021 15:50:43 -0700 Subject: [PATCH] Slight change in weld length calculation --- lib/Perl/Tidy/Formatter.pm | 41 ++++++++++++++++++++++++++++++++++---- local-docs/BugLog.pod | 10 +++++++++- 2 files changed, 46 insertions(+), 5 deletions(-) diff --git a/lib/Perl/Tidy/Formatter.pm b/lib/Perl/Tidy/Formatter.pm index 5134f053..c7181dc8 100644 --- a/lib/Perl/Tidy/Formatter.pm +++ b/lib/Perl/Tidy/Formatter.pm @@ -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; + diff --git a/local-docs/BugLog.pod b/local-docs/BugLog.pod index 5911c94d..73e23eda 100644 --- a/local-docs/BugLog.pod +++ b/local-docs/BugLog.pod @@ -3,6 +3,14 @@ =over 4 +=item B + +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 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 -- 2.39.5