From 62e5b01485a741bfa025a6773891112911b445f1 Mon Sep 17 00:00:00 2001 From: Steve Hancock Date: Sat, 21 Aug 2021 13:18:32 -0700 Subject: [PATCH] Fix formatting instability issue b1194 --- dev-bin/run_convergence_tests.pl.data | 23 ++++++++++++++++ lib/Perl/Tidy/Formatter.pm | 38 ++++++++++++--------------- local-docs/BugLog.pod | 10 +++++++ 3 files changed, 50 insertions(+), 21 deletions(-) diff --git a/dev-bin/run_convergence_tests.pl.data b/dev-bin/run_convergence_tests.pl.data index e97ee529..1f63ba01 100644 --- a/dev-bin/run_convergence_tests.pl.data +++ b/dev-bin/run_convergence_tests.pl.data @@ -7161,6 +7161,29 @@ print --maximum-line-length=49 --square-bracket-vertical-tightness-closing=1 +==> b1194.in <== +# S1 + is(0+keys%mani,0+@files,"no duplicate files in MANIFEST") + or diag( + join("\n ","Duplicates:",grep$mani{$_}>1, + keys%mani) + ); +# S2 + is(0+keys%mani,0+@files,"no duplicate files in MANIFEST") + or + diag(join("\n ","Duplicates:",grep$mani{$_}>1,keys%mani)); + + +==> b1194.par <== +--noadd-whitespace +--continuation-indentation=0 +--ignore-old-breakpoints +--indent-columns=10 +--line-up-parentheses +--maximum-line-length=70 +--paren-vertical-tightness=2 +--weld-nested-containers + ==> b120.in <== # Same as bug96 # State 1 diff --git a/lib/Perl/Tidy/Formatter.pm b/lib/Perl/Tidy/Formatter.pm index 3cc160da..e388158f 100644 --- a/lib/Perl/Tidy/Formatter.pm +++ b/lib/Perl/Tidy/Formatter.pm @@ -6731,8 +6731,15 @@ sub parent_seqno_by_K { while ( defined($Ktest) ) { my $type = $rLL->[$Ktest]->[_TYPE_]; + # if next container token is opening, we want its parent container + if ( $is_opening_type{$type} ) { + my $type_sequence = $rLL->[$Ktest]->[_TYPE_SEQUENCE_]; + $parent_seqno = $self->[_rparent_of_seqno_]->{$type_sequence}; + last; + } + # if next container token is closing, it is the parent seqno - if ( $is_closing_type{$type} ) { + elsif ( $is_closing_type{$type} ) { my $type_sequence = $rLL->[$Ktest]->[_TYPE_SEQUENCE_]; if ( $Ktest > $KK ) { $parent_seqno = $type_sequence; @@ -6743,13 +6750,6 @@ sub parent_seqno_by_K { last; } - # if next container token is opening, we want its parent container - elsif ( $is_opening_type{$type} ) { - my $type_sequence = $rLL->[$Ktest]->[_TYPE_SEQUENCE_]; - $parent_seqno = $self->[_rparent_of_seqno_]->{$type_sequence}; - last; - } - # not a container - must be ternary - keep going $Ktest = $rLL->[$Ktest]->[_KNEXT_SEQ_ITEM_]; } @@ -8064,19 +8064,6 @@ EOM else { $is_one_line_weld = 1; } - - # If an apparent one-line weld might have been created by - # -vt and -lp, then do not mark as a one-line weld. - # This condition added to fix b1183. - # Added block type test to fix b1191 - if ( $is_one_line_weld - && $rOpts_line_up_parentheses - && $opening_vertical_tightness{$token_oo} - && !$rblock_type_of_seqno->{$inner_seqno} - && !$ris_excluded_lp_container->{$outer_seqno} ) - { - $is_one_line_weld = 0; - } } } @@ -22103,6 +22090,7 @@ sub set_vertical_tightness_flags { if ($rOpts_freeze_whitespace); my $rwant_container_open = $self->[_rwant_container_open_]; + my $rK_weld_left = $self->[_rK_weld_left_]; # Uses these global parameters: # $rOpts_block_brace_tightness @@ -22149,6 +22137,14 @@ sub set_vertical_tightness_flags { # requested my $ovt = $opening_vertical_tightness{$token_end}; my $iend_next = $ri_last->[ $n + 1 ]; + + # Turn off the -vt flag if the next line ends in a weld. + # This avoids an instability with one-line welds (fixes b1183). + my $type_end_next = $types_to_go[$iend_next]; + $ovt = 0 + if ( $rK_weld_left->{ $K_to_go[$iend_next] } + && $is_closing_type{$type_end_next} ); + unless ( $ovt < 2 && ( $nesting_depth_to_go[ $iend_next + 1 ] != diff --git a/local-docs/BugLog.pod b/local-docs/BugLog.pod index 994d9607..d7d8a7df 100644 --- a/local-docs/BugLog.pod +++ b/local-docs/BugLog.pod @@ -2,6 +2,16 @@ =over 4 +=item B + +Testing with random parameters produced a case of unstable formatting +which is fixed with this update. + +This fixes case b1194, and at the same time it simplifies the logic +which handles issues b1183 and b1191. + +21 Aug 2021. + =item B This update fixes some problems found in random testing with tab characters. -- 2.39.5