Fix possible welding instability in ternary after fat comma
authorSteve Hancock <perltidy@users.sourceforge.net>
Sun, 18 Jul 2021 16:46:47 +0000 (09:46 -0700)
committerSteve Hancock <perltidy@users.sourceforge.net>
Sun, 18 Jul 2021 16:46:47 +0000 (09:46 -0700)
dev-bin/run_convergence_tests.pl.data
lib/Perl/Tidy/Formatter.pm
local-docs/BugLog.pod

index 1d8cda4c646d82f9ec7249ee268e5bf7f1f8fca0..988f9b5a0732fa410401e47422d32ede03e30901 100644 (file)
@@ -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
 
index 6d4c2785a94e6a3feb2238749b25d6fff0739d91..cdca0f1ad2c20c1ecca8bc957a51331020dd2297 100644 (file)
@@ -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
index ee15a1578c59bd8df9a424adf19ff5932e3f1529..1ca07254d416189ab272e6b562094a832c08404c 100644 (file)
@@ -2,6 +2,36 @@
 
 =over 4
 
+=item B<Fix possible welding instability in ternary after fat comma>
+
+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<Fix mis-tokenization before pointer>
 
 Random testing produced the following case in which formatting was unstable because