From 6dd53fba34c95bf5319c0c98c50a5a5757d33efc Mon Sep 17 00:00:00 2001 From: Steve Hancock Date: Fri, 30 Jul 2021 17:25:08 -0700 Subject: [PATCH] Fix edge case of formatting instability, b1184 --- dev-bin/run_convergence_tests.pl.data | 25 +++++++++++++++++++++++ lib/Perl/Tidy/Formatter.pm | 29 ++++++++++++++++++--------- local-docs/BugLog.pod | 9 +++++++++ 3 files changed, 54 insertions(+), 9 deletions(-) diff --git a/dev-bin/run_convergence_tests.pl.data b/dev-bin/run_convergence_tests.pl.data index 3da6364c..2fe90564 100644 --- a/dev-bin/run_convergence_tests.pl.data +++ b/dev-bin/run_convergence_tests.pl.data @@ -6855,6 +6855,31 @@ $orders= SearchOrders( { --maximum-line-length=55 --weld-nested-containers +==> b1184.in <== +# S1 +ok( ( Win32::GetFullPathName( substr + ( $cwd, 2 ) ) + )[0], + "$dir\\" +); + +# S2 +ok( ( Win32::GetFullPathName( + substr( + $cwd, 2 + ) + ) + )[0], + "$dir\\" +); + +==> b1184.par <== +--extended-continuation-indentation +--line-up-parentheses +--maximum-line-length=30 +--weld-nested-containers +--vertical-tightness=2 + ==> b120.in <== # Same as bug96 # State 1 diff --git a/lib/Perl/Tidy/Formatter.pm b/lib/Perl/Tidy/Formatter.pm index bbdf577d..0eae6b4b 100644 --- a/lib/Perl/Tidy/Formatter.pm +++ b/lib/Perl/Tidy/Formatter.pm @@ -7479,18 +7479,23 @@ sub is_excluded_weld { return $match; } -# types needed for welding RULE 6 +# hashes to simplify welding logic my %type_ok_after_bareword; - my %is_ternary; +my %has_tight_paren; BEGIN { + # types needed for welding RULE 6 my @q = qw# => -> { ( [ #; @type_ok_after_bareword{@q} = (1) x scalar(@q); @q = qw( ? : ); @is_ternary{@q} = (1) x scalar(@q); + + # these types do not 'like' to be separated from a following paren + @q = qw(w i q Q G C Z U); + @{has_tight_paren}{@q} = (1) x scalar(@q); } use constant DEBUG_WELD => 0; @@ -8163,13 +8168,19 @@ EOM if ($do_not_weld_rule) { # After neglecting a pair, we start measuring from start of point io - my $starting_level = $inner_opening->[_LEVEL_]; - my $starting_ci_level = $inner_opening->[_CI_LEVEL_]; - $starting_lentot = - $self->cumulative_length_before_K($Kinner_opening); - $maximum_text_length = - $maximum_text_length_at_level[$starting_level] - - $starting_ci_level * $rOpts_continuation_indentation; + # ... but not if previous type does not like to be separated from + # its container (fixes case b1184) + my $Kprev = $self->K_previous_nonblank($Kinner_opening); + my $type_prev = defined($Kprev) ? $rLL->[$Kprev]->[_TYPE_] : 'w'; + if ( !$has_tight_paren{$type_prev} ) { + my $starting_level = $inner_opening->[_LEVEL_]; + my $starting_ci_level = $inner_opening->[_CI_LEVEL_]; + $starting_lentot = + $self->cumulative_length_before_K($Kinner_opening); + $maximum_text_length = + $maximum_text_length_at_level[$starting_level] - + $starting_ci_level * $rOpts_continuation_indentation; + } if (DEBUG_WELD) { $Msg .= "Not welding due to RULE $do_not_weld_rule\n"; diff --git a/local-docs/BugLog.pod b/local-docs/BugLog.pod index 74aea260..603f7ce8 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 welding instability involving +parameters -wn, -vt=n, -lp. This update fixes the problem. + +This fixes case b1184. + +28 Jul 2021. + =item B. Testing with random parameters produced a case of welding instability involving -- 2.39.5