From b949215732ea8a1f0f61f85a9b0d49425321bd25 Mon Sep 17 00:00:00 2001 From: Steve Hancock Date: Tue, 10 Aug 2021 08:41:42 -0700 Subject: [PATCH] Fix formatting instability, b1192 --- dev-bin/run_convergence_tests.pl.data | 18 ++++++++++++++++++ lib/Perl/Tidy/Formatter.pm | 13 +++++++++++-- local-docs/BugLog.pod | 22 ++++++++++++++++++++++ 3 files changed, 51 insertions(+), 2 deletions(-) diff --git a/dev-bin/run_convergence_tests.pl.data b/dev-bin/run_convergence_tests.pl.data index fc38ffa3..46e7d511 100644 --- a/dev-bin/run_convergence_tests.pl.data +++ b/dev-bin/run_convergence_tests.pl.data @@ -7121,6 +7121,24 @@ print --paren-vertical-tightness=1 --weld-nested-containers +==> b1192.in <== +# S1 + @EXPORT = + ( @{$EXPORT_TAGS{standard}}, ); + +# S2 + @EXPORT = ( + @{$EXPORT_TAGS{standard}}, + ); + +==> b1192.par <== +--brace-tightness=2 +--continuation-indentation=4 +--ignore-old-breakpoints +--indent-columns=10 +--line-up-parentheses +--maximum-line-length=48 + ==> b120.in <== # Same as bug96 # State 1 diff --git a/lib/Perl/Tidy/Formatter.pm b/lib/Perl/Tidy/Formatter.pm index c49060b0..71e36532 100644 --- a/lib/Perl/Tidy/Formatter.pm +++ b/lib/Perl/Tidy/Formatter.pm @@ -16029,6 +16029,13 @@ sub set_continuation_breaks { my $bp_count = 0; my $do_not_break_apart = 0; + # Do not break a list unless there are some non-line-ending commas. + # This avoids getting different results with only non-essential commas, + # and fixes b1192. + my $seqno = $type_sequence_stack[$dd]; + my $real_comma_count = + $seqno ? $self->[_rtype_count_by_seqno_]->{$seqno}->{','} : 1; + # anything to do? if ( $item_count_stack[$dd] ) { @@ -16038,7 +16045,7 @@ sub set_continuation_breaks { } # handle commas within containers... - else { + elsif ($real_comma_count) { my $fbc = get_forced_breakpoint_count(); # always open comma lists not preceded by keywords, @@ -16289,7 +16296,9 @@ sub set_continuation_breaks { my $i_line_start = -1; my $i_last_colon = -1; - # loop over all tokens in this batch + ######################################### + # Main loop over all tokens in this batch + ######################################### while ( ++$i <= $max_index_to_go ) { if ( $type ne 'b' ) { $i_last_nonblank_token = $i - 1; diff --git a/local-docs/BugLog.pod b/local-docs/BugLog.pod index 46aad0d3..989c0585 100644 --- a/local-docs/BugLog.pod +++ b/local-docs/BugLog.pod @@ -2,6 +2,28 @@ =over 4 +=item B + +Testing with random parameters produced unstable formatting with the +following snippet when run with some unusual parameters: + + @EXPORT = + ( @{$EXPORT_TAGS{standard}}, ); + +It was also be formatted as + + @EXPORT = ( + @{$EXPORT_TAGS{standard}}, + ); + +The problem was that a list formatting style was turning on and off due to the +the needless terminal comma within the parens. A patch was made to ignore +commas like this when deciding if list formatting should be used. + +This fixes case b1192. + +10 Aug 2021. + =item B Random testing produced an instability involving an unusual parameter -- 2.39.5