From 12ae46be90a28e740e9504b617483f8c02b1e393 Mon Sep 17 00:00:00 2001 From: Steve Hancock Date: Sun, 18 Jul 2021 09:46:47 -0700 Subject: [PATCH] Fix possible welding instability in ternary after fat comma --- dev-bin/run_convergence_tests.pl.data | 41 +++++++++++++++++++++++++++ lib/Perl/Tidy/Formatter.pm | 12 +++++++- local-docs/BugLog.pod | 30 ++++++++++++++++++++ 3 files changed, 82 insertions(+), 1 deletion(-) diff --git a/dev-bin/run_convergence_tests.pl.data b/dev-bin/run_convergence_tests.pl.data index 1d8cda4c..988f9b5a 100644 --- a/dev-bin/run_convergence_tests.pl.data +++ b/dev-bin/run_convergence_tests.pl.data @@ -6548,6 +6548,47 @@ ok('[{"1":[5]}]' eq --vertical-tightness=2 --weld-nested-containers +==> b1174.in <== +# S1 + +if ( $op and $op eq 'do_search' ) { + @{$invoices} = + GetInvoices( + shipmentdatefrom => + $shipmentdatefrom ? output_pref( { + str => $shipmentdatefrom, + dateformat => 'iso' + } ) + : undef, + publicationyear => $publicationyear, + ); +} + +# S2 + +if ( $op and $op eq 'do_search' ) { + @{$invoices} = + GetInvoices( + shipmentdatefrom => + $shipmentdatefrom + ? output_pref( + { + str => $shipmentdatefrom, + dateformat => 'iso' + } + ) + : undef, + publicationyear => $publicationyear, + ); +} + +==> b1174.par <== +--extended-continuation-indentation +--line-up-parentheses +--maximum-line-length=38 +--variable-maximum-line-length +--weld-nested-containers + ==> b1175.in <== # S1 diff --git a/lib/Perl/Tidy/Formatter.pm b/lib/Perl/Tidy/Formatter.pm index 6d4c2785..cdca0f1a 100644 --- a/lib/Perl/Tidy/Formatter.pm +++ b/lib/Perl/Tidy/Formatter.pm @@ -7433,7 +7433,17 @@ sub setup_new_weld_measurements { if ( $rOpts_line_up_parentheses || $want_break_before{$type_prev} ) { - if ( substr( $type_prev, 0, 1 ) eq '=' ) { + + # If there are other sequence items between the start of this line + # and the opening token in question, then do not include tokens on + # the previous line in length calculations. This check added to + # fix case b1174 which had a '?' on the line + my $no_previous_seq_item = $Kref == $Kouter_opening + || $rLL->[$Kref]->[_KNEXT_SEQ_ITEM_] == $Kouter_opening; + + if ( $no_previous_seq_item + && substr( $type_prev, 0, 1 ) eq '=' ) + { $Kref = $Kprev; # Fix for b1144 and b1112: backup to the first nonblank diff --git a/local-docs/BugLog.pod b/local-docs/BugLog.pod index ee15a157..1ca07254 100644 --- a/local-docs/BugLog.pod +++ b/local-docs/BugLog.pod @@ -2,6 +2,36 @@ =over 4 +=item B + +Random testing produced a case of formatting instability involving welding +within a ternary expression following a fat comma: + + if ( $op and $op eq 'do_search' ) { + @{$invoices} = + GetInvoices( + shipmentdatefrom => + $shipmentdatefrom ? output_pref( { + str => $shipmentdatefrom, + dateformat => 'iso' + } ) + : undef, + publicationyear => $publicationyear, + ); + } + +when the following specific parameters were used + + --extended-continuation-indentation + --line-up-parentheses + --maximum-line-length=38 + --variable-maximum-line-length + --weld-nested-containers + +This update fixes this issue, case b1174. + +18 Jul 2021. + =item B Random testing produced the following case in which formatting was unstable because -- 2.39.5