From f697252712cd23e3c0983cf0d5eedee9f7dd93b4 Mon Sep 17 00:00:00 2001 From: Steve Hancock Date: Mon, 3 Jan 2022 07:29:48 -0800 Subject: [PATCH] fix issues b1270, b1303 (-bom and -pvt conflicts) --- dev-bin/run_convergence_tests.pl.data | 40 +++++++++++++++++++++++++ lib/Perl/Tidy/Formatter.pm | 43 +++++++++++++++++---------- 2 files changed, 67 insertions(+), 16 deletions(-) diff --git a/dev-bin/run_convergence_tests.pl.data b/dev-bin/run_convergence_tests.pl.data index 9526caa0..23980114 100644 --- a/dev-bin/run_convergence_tests.pl.data +++ b/dev-bin/run_convergence_tests.pl.data @@ -8471,6 +8471,26 @@ function( --maximum-line-length=30 --variable-maximum-line-length +==> b1270.in <== + $this->{SymAutoCor} = ( + PDL->zeroes( + $n * + 2 - 1 + )->float + ); + + $this->{SymAutoCor} = + ( PDL->zeroes( $n * + 2 - 1 + )->float ); + + +==> b1270.par <== +--break-at-old-method-breakpoints +--indent-columns=10 +--maximum-line-length=37 +--vertical-tightness=2 + ==> b1272.in <== $this->{Normals} = ( @@ -8723,6 +8743,26 @@ subtest '->save' => sub { --space-function-paren --vertical-tightness=1 +==> b1303.in <== +if ( + ( + $response = $browser->request($curreq) + )->is_error() ); + +if (( $response = $browser->request($curreq) +)->is_error()); + + +==> b1303.par <== +--break-at-old-method-breakpoints +--continuation-indentation=9 +--extended-line-up-parentheses +--indent-columns=2 +--keyword-paren-inner-tightness=2 +--maximum-line-length=53 +--paren-vertical-tightness-closing=2 +--novalign-code + ==> b131.in <== unless ( open( SCORE, "+>>$Score_File" ) ) diff --git a/lib/Perl/Tidy/Formatter.pm b/lib/Perl/Tidy/Formatter.pm index be64b967..ee259bc7 100644 --- a/lib/Perl/Tidy/Formatter.pm +++ b/lib/Perl/Tidy/Formatter.pm @@ -7628,19 +7628,17 @@ sub keep_old_line_breaks { my $seqno = $rLL->[$Kfirst]->[_TYPE_SEQUENCE_]; next unless ($seqno); - # Patch to avoid blinkers: but do not do this unless the - # container holds a list, or the opening and closing parens are - # separated by more than one* line. - # Fixes case b977. - # *To fix b1215: use min line count = 2 if -vt=n to avoid - # oscillations with function of opening vertical tightness. - my $lc_min = $opening_vertical_tightness{$token} ? 2 : 1; - next - if ( - !$ris_list_by_seqno->{$seqno} - && ( !$ris_broken_container->{$seqno} - || $ris_broken_container->{$seqno} <= $lc_min ) - ); + # Note: in previous versions there was a fix here to avoid + # instability between conflicting -bom and -pvt or -pvtc flags. + # The fix skipped -bom for a small line difference. But this + # was troublesome, and instead the fix has been moved to + # sub set_vertical_tightness_flags where priority is given to + # the -bom flag over -pvt and -pvtc flags. Both opening and + # closing paren flags are involved because even though -bom only + # requests breaking before the closing paren, automated logic + # opens the opening paren when the closing paren opens. + # Relevant cases are b977, b1215, b1270, b1303 + $rwant_container_open->{$seqno} = 1; } } @@ -10666,7 +10664,7 @@ sub collapsed_lengths { # stabilize by itself after one or two iterations. # - So, not doing this for now - # TESTING: Include length to a comma ending this line + # Include length to a comma ending this line if ( $interrupted_list_rule && $rLL->[$K_terminal]->[_TYPE_] eq ',' ) { @@ -10684,9 +10682,9 @@ sub collapsed_lengths { { $Kbeg++; } + my $len = $rLL->[$Kend]->[_CUMULATIVE_LENGTH_] - $rLL->[$Kbeg]->[_CUMULATIVE_LENGTH_]; - if ( $len > $max_prong_len ) { $max_prong_len = $len } } @@ -24816,7 +24814,6 @@ sub set_vertical_tightness_flags { ) ) { - # avoid multiple jumps in nesting depth in one line if # requested my $ovt = $opening_vertical_tightness{$token_end}; @@ -24829,6 +24826,13 @@ sub set_vertical_tightness_flags { if ( $self->[_rK_weld_left_]->{ $K_to_go[$iend_next] } && $is_closing_type{$type_end_next} ); + # Avoid conflict of -bom and -pt=1 or -pt=2, fixes b1270 + # See similar patch above for $cvt. + my $seqno = $type_sequence_to_go[$iend]; + if ( $ovt && $self->[_rwant_container_open_]->{$seqno} ) { + $ovt = 0; + } + unless ( $ovt < 2 && ( $nesting_depth_to_go[ $iend_next + 1 ] != @@ -24862,6 +24866,13 @@ sub set_vertical_tightness_flags { my $ovt = $opening_vertical_tightness{$token_next}; my $cvt = $closing_vertical_tightness{$token_next}; + # Avoid conflict of -bom and -pvt=1 or -pvt=2, fixes b977, b1303 + # See similar patch above for $ovt. + my $seqno = $type_sequence_to_go[$ibeg_next]; + if ( $cvt && $self->[_rwant_container_open_]->{$seqno} ) { + $cvt = 0; + } + # Implement cvt=3: like cvt=0 for assigned structures, like cvt=1 # otherwise. Added for rt136417. if ( $cvt == 3 ) { -- 2.39.5