From e84f5fa9099b623f4cb95e58dfaad4b2a9ddc2e9 Mon Sep 17 00:00:00 2001 From: Steve Hancock Date: Fri, 23 Dec 2022 16:24:10 -0800 Subject: [PATCH] fix c167 --- lib/Perl/Tidy.pm | 5 +++++ lib/Perl/Tidy/Formatter.pm | 23 ++++++++++++++++++----- 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/lib/Perl/Tidy.pm b/lib/Perl/Tidy.pm index c66da71d..15018738 100644 --- a/lib/Perl/Tidy.pm +++ b/lib/Perl/Tidy.pm @@ -4385,6 +4385,11 @@ EOM } } + # Large values of -scl can cause convergence problems, issue c167 + if ( $rOpts->{'short-concatenation-item-length'} > 12 ) { + $rOpts->{'short-concatenation-item-length'} = 12; + } + # The freeze-whitespace option is currently a derived option which has its # own key $rOpts->{'freeze-whitespace'} = !$rOpts->{'add-whitespace'} diff --git a/lib/Perl/Tidy/Formatter.pm b/lib/Perl/Tidy/Formatter.pm index e0178c5d..d0353293 100644 --- a/lib/Perl/Tidy/Formatter.pm +++ b/lib/Perl/Tidy/Formatter.pm @@ -17874,8 +17874,10 @@ sub break_equals { # maximum is large enough that this should never happen. $it_count++; if ( $it_count > $it_count_max ) { + my $KK = $K_to_go[0]; + my $lno = $self->[_rLL_]->[$KK]->[_LINE_INDEX_]; DEVEL_MODE && Fault(<[_rLL_]->[$KK]->[_LINE_INDEX_]; Fault( -"Program bug-infinite loop in recombine breakpoints\n" +"Program bug-infinite loop in recombine breakpoints near line $lno\n" ); } $more_to_do = 0; @@ -18914,6 +18918,10 @@ EOM # do not recombine lines with leading '.' elsif ( $type_ibeg_2 eq '.' ) { my $i_next_nonblank = min( $inext_to_go[$ibeg_2], $iend_2 ); + my $summed_len_1 = $summed_lengths_to_go[ $iend_1 + 1 ] - + $summed_lengths_to_go[$ibeg_1]; + my $summed_len_2 = $summed_lengths_to_go[ $iend_2 + 1 ] - + $summed_lengths_to_go[$ibeg_2]; return unless ( @@ -18933,11 +18941,16 @@ EOM # ... or this would strand a short quote , like this # . "some long quote" # . "\n"; - - || ( $types_to_go[$i_next_nonblank] eq 'Q' + || ( + $types_to_go[$i_next_nonblank] eq 'Q' && $i_next_nonblank >= $iend_2 - 1 && $token_lengths_to_go[$i_next_nonblank] < - $rOpts_short_concatenation_item_length ) + $rOpts_short_concatenation_item_length + + # additional constraints to fix c167 + && ( $types_to_go[$iend_1] ne 'Q' + || $summed_len_2 < $summed_len_1 ) + ) ); } -- 2.39.5