]> git.donarmstrong.com Git - perltidy.git/commitdiff
Fix formatting instability, b1192
authorSteve Hancock <perltidy@users.sourceforge.net>
Tue, 10 Aug 2021 15:41:42 +0000 (08:41 -0700)
committerSteve Hancock <perltidy@users.sourceforge.net>
Tue, 10 Aug 2021 15:41:42 +0000 (08:41 -0700)
dev-bin/run_convergence_tests.pl.data
lib/Perl/Tidy/Formatter.pm
local-docs/BugLog.pod

index fc38ffa3e40264ee3396fef581cef7c491cd79f7..46e7d51180c5b7e34da1f86549ad1ad0b8decbea 100644 (file)
@@ -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
index c49060b0dc7cfaa22d7b6eff40d29ac2cdcedfe9..71e3653283da3852f7d4a25c916a23a7bf04fb38 100644 (file)
@@ -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;
index 46aad0d327be811c768e6a8036e31ff94130c89f..989c058594fded1691523fa65264aee22c11cf73 100644 (file)
@@ -2,6 +2,28 @@
 
 =over 4
 
+=item B<Fix formatting instability, b1192>
+
+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<Fix formatting instability, b1191>
 
 Random testing produced an instability involving an unusual parameter