From f3dbee1eb437a28f7b614b752232f3bd938bde39 Mon Sep 17 00:00:00 2001 From: Steve Hancock Date: Mon, 2 Aug 2021 18:57:04 -0700 Subject: [PATCH] Fix edge case of formatting instability, b1186 --- dev-bin/run_convergence_tests.pl.data | 30 +++++++++++++++++++++++++++ lib/Perl/Tidy/Formatter.pm | 20 +++++++++++++----- local-docs/BugLog.pod | 9 ++++++++ 3 files changed, 54 insertions(+), 5 deletions(-) diff --git a/dev-bin/run_convergence_tests.pl.data b/dev-bin/run_convergence_tests.pl.data index 2fe5c841..f1461684 100644 --- a/dev-bin/run_convergence_tests.pl.data +++ b/dev-bin/run_convergence_tests.pl.data @@ -6931,6 +6931,36 @@ ok( ( Win32::GetFullPathName( --vertical-tightness=2 --weld-nested-containers +==> b1186.in <== +# S1 +sub null_to_zzempty { } +sub entab { + + return + $table->{ + null_to_zzempty ( $row ) + }->{ null_to_zzempty ( $col ) }; +} + +# S2 +sub null_to_zzemptY { } + +sub entaB { + + return + $table->{ null_to_zzemptY ( + $row ) } + ->{ null_to_zzemptY ( $col ) }; +} + +==> b1186.par <== +--indent-columns=10 +--line-up-parentheses +--maximum-line-length=44 +--paren-tightness=0 +--paren-vertical-tightness=2 +--space-function-paren + ==> b120.in <== # Same as bug96 # State 1 diff --git a/lib/Perl/Tidy/Formatter.pm b/lib/Perl/Tidy/Formatter.pm index d2d1bc52..5c801e73 100644 --- a/lib/Perl/Tidy/Formatter.pm +++ b/lib/Perl/Tidy/Formatter.pm @@ -17140,10 +17140,12 @@ my %is_kwiZ; BEGIN { # Added 'w' to fix b1172 - my @q = qw(k w i Z); + my @q = qw(k w i Z ->); @is_kwiZ{@q} = (1) x scalar(@q); } +use constant DEBUG_FIND_START => 0; + sub find_token_starting_list { # When testing to see if a block will fit on one line, some @@ -17169,7 +17171,14 @@ sub find_token_starting_list { # a previous comma is a good break point # $i_opening_minus = $i_opening_paren; } - elsif ( $tokens_to_go[$i_opening_paren] eq '(' ) { + + elsif ( + $tokens_to_go[$i_opening_paren] eq '(' + + # non-parens added here to fix case b1186 + || $is_kwiZ{$type_prev_nb} + ) + { $i_opening_minus = $im1; # Walk back to improve length estimate... @@ -17184,11 +17193,12 @@ sub find_token_starting_list { if ( $types_to_go[$i_opening_minus] eq 'b' ) { $i_opening_minus++ } } - # Handle non-parens - elsif ( $is_kwiZ{$type_prev_nb} ) { $i_opening_minus = $iprev_nb } - RETURN: + DEBUG_FIND_START && print < im=$i_opening_minus tok=$tokens_to_go[$i_opening_minus] +EOM + return $i_opening_minus; } diff --git a/local-docs/BugLog.pod b/local-docs/BugLog.pod index dadd9848..cf543f87 100644 --- a/local-docs/BugLog.pod +++ b/local-docs/BugLog.pod @@ -2,6 +2,15 @@ =over 4 +=item B. + +Testing with random parameters produced a case of instability involving +parameter -lp -pvt=n and a short maximum line length. + +This fixes case b1186. + +2 Aug 2021. + =item B. Testing with random parameters produced a case of welding instability involving -- 2.39.5