From 21094b00a9598f5ba50082991f61544d51bc6f8b Mon Sep 17 00:00:00 2001 From: Steve Hancock Date: Tue, 5 Apr 2022 08:39:47 -0700 Subject: [PATCH] fix rare instability found in testing, issue b1331 --- dev-bin/run_convergence_tests.pl.data | 22 ++++++++++++++++++++++ lib/Perl/Tidy/Formatter.pm | 10 ++++++++-- 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/dev-bin/run_convergence_tests.pl.data b/dev-bin/run_convergence_tests.pl.data index d1d4196b..70f0d039 100644 --- a/dev-bin/run_convergence_tests.pl.data +++ b/dev-bin/run_convergence_tests.pl.data @@ -9643,6 +9643,28 @@ WriteMakefile( --indent-columns=1 --square-bracket-vertical-tightness-closing=1 +==> b1331.in <== +# S1 +WriteMakefile PREREQ_PM => + { # e.g., Module::Name => 1.1 + 'ExtUtils::MakeMaker' => 5.45, + 'LWP::UserAgent' => 0, + }, + ; + +# S2 +WriteMakefile PREREQ_PM => + { # e.g., Module::Name => 1.1 + 'ExtUtils::MakeMaker' => 5.45, + 'LWP::UserAgent' => 0, + }, + ; + + +==> b1331.par <== +--extended-line-up-parentheses +--maximum-line-length=32 + ==> b1332.in <== # S1 $b->configure ( diff --git a/lib/Perl/Tidy/Formatter.pm b/lib/Perl/Tidy/Formatter.pm index 533c3b5d..eecf0284 100644 --- a/lib/Perl/Tidy/Formatter.pm +++ b/lib/Perl/Tidy/Formatter.pm @@ -10926,7 +10926,7 @@ sub collapsed_lengths { defined($K_c) && $rLL->[$K_terminal]->[_TYPE_] eq ',' - # Ignore a terminal comma, causes instability (b1297, b1330) + # Ignore if terminal comma, causes instability (b1297, b1330) && ( $K_c - $K_terminal > 2 || ( $K_c - $K_terminal == 2 @@ -10949,6 +10949,12 @@ sub collapsed_lengths { my $leng = $rLL->[$Kend]->[_CUMULATIVE_LENGTH_] - $rLL->[ $K_first - 1 ]->[_CUMULATIVE_LENGTH_]; + # Fix for b1331: at a broken => item, include the length of + # the previous half of the item plus one for the missing space + if ( $last_nonblank_type eq '=>' ) { + $leng += $len + 1; + } + if ( $leng > $max_prong_len ) { $max_prong_len = $leng } } } @@ -11179,7 +11185,7 @@ EOM if ( $len > $max_prong_len ) { $max_prong_len = $len } # but only include one => per item - if ( $last_nonblank_type eq '=>' ) { $len = $token_length } + $len = $token_length; } # include everthing to end of line after a here target -- 2.39.5