]> git.donarmstrong.com Git - perltidy.git/commitdiff
Avoid instability of combination -bbx=2 -lp and -xci
authorSteve Hancock <perltidy@users.sourceforge.net>
Sun, 2 May 2021 03:13:38 +0000 (20:13 -0700)
committerSteve Hancock <perltidy@users.sourceforge.net>
Sun, 2 May 2021 03:13:38 +0000 (20:13 -0700)
lib/Perl/Tidy/Formatter.pm
local-docs/BugLog.pod

index 02947bf04d3b2b94d622ebb0d8f3936430cd2ed9..3410b651dcd57ecec99414e1f1c75cea447a5120 100644 (file)
@@ -8476,19 +8476,19 @@ sub break_before_list_opening_containers {
         #################################################################
 
         my $KK = $K_opening_container->{$seqno};
+        next if ( $rLL->[$KK]->[_BLOCK_TYPE_] );
 
-        my $is_list           = $self->is_list_by_seqno($seqno);
-        my $has_list          = $rhas_list->{$seqno};
-        my $has_broken_list   = $rhas_broken_list->{$seqno};
-        my $has_list_with_lec = $rhas_broken_list_with_lec->{$seqno};
-
-        # This must be a list (this will exclude all code blocks)
-        # or contain a list.
+        # This must be a list or contain a list.
         # Note1: switched from 'has_broken_list' to 'has_list' to fix b1024.
         # Note2: 'has_list' holds the depth to the sub-list.  We will require
         #  a depth of just 1
+        my $is_list  = $self->is_list_by_seqno($seqno);
+        my $has_list = $rhas_list->{$seqno};
         next unless ( $is_list || $has_list && $has_list == 1 );
 
+        my $has_broken_list   = $rhas_broken_list->{$seqno};
+        my $has_list_with_lec = $rhas_broken_list_with_lec->{$seqno};
+
         # Only for types of container tokens with a non-default break option
         my $token        = $rLL->[$KK]->[_TOKEN_];
         my $break_option = $break_before_container_types{$token};
@@ -8520,12 +8520,12 @@ sub break_before_list_opening_containers {
             next unless ( $KK == $Kfirst );
         }
 
-        # -bbx=2 = only if complex list, meaning:
-        #  - this list contains a broken list with line-ending comma, or
-        #  - this list is contained in a broken list
+        # -bbx=2 => apply this style only for a 'complex' list
         elsif ( $break_option == 2 ) {
 
+            #  break if this list contains a broken list with line-ending comma
             my $ok_to_break = $has_list_with_lec;
+
             if ( !$ok_to_break ) {
 
                 # Turn off -xci if -bbx=2 and this container has a sublist but
@@ -8537,10 +8537,21 @@ sub break_before_list_opening_containers {
                 if ($has_list) { $rno_xci_by_seqno->{$seqno} = 1 }
 
                 my $parent = $rparent_of_seqno->{$seqno};
-                $ok_to_break = $self->is_list_by_seqno($parent);
+                $ok_to_break ||= $self->is_list_by_seqno($parent);
+            }
+
+            # Patch to fix b1099 for -lp
+            #  ok in -lp mode if this is a list which contains a list
+            if ( !$ok_to_break && $rOpts_line_up_parentheses ) {
+                $ok_to_break ||= $is_list && $has_list;
             }
 
             next unless ($ok_to_break);
+
+            # Patch: turn off -xci if -bbx=2 and -lp
+            # This fixes cases b1090 b1095 b1101 b1116 b1118 b1121 b1122
+            $rno_xci_by_seqno->{$seqno} = 1 if ($rOpts_line_up_parentheses);
+
         }
 
         # -bbx=3 = always break
@@ -15490,6 +15501,8 @@ sub set_continuation_breaks {
         my $rOpts_break_at_old_ternary_breakpoints =
           $rOpts->{'break-at-old-ternary-breakpoints'};
 
+        my $rLL                  = $self->[_rLL_];
+        my $ris_list_by_seqno    = $self->[_ris_list_by_seqno_];
         my $ris_broken_container = $self->[_ris_broken_container_];
 
         $starting_depth = $nesting_depth_to_go[0];
index 26bc83caafa6e7ae72268e849049aae16b67417e..377f1ba751e441eb2c1a47dbc1b0ffbce2667319 100644 (file)
@@ -2,6 +2,16 @@
 
 =over 4
 
+=item B<Avoid instability of combination -bbx=2 -lp and -xci>
+
+Random testing produced several cases in which the flags -bbx=2 -lp and -xci
+were causing formatting instability.  The fix is to locally turn off -xci when
+-lp and -bbx=2 are in effect.  This is an extension of commit 2b05051.
+
+This fixes cases b1090 b1095 b1101 b1116 b1118 b1121 b1122 b1099
+
+1 May 2021.
+
 =item B<Restrict use of flag -cab=3 to simple structures>
 
 Logic was added to turn off -cab=3 in complex structures.  Otherwise,
@@ -32,7 +42,7 @@ formatting of the following snippet was unstable:
 
 This update fixes cases b1096 b1113.
 
-29 Apr 2021.
+29 Apr 2021, 32a1830.
 
 =item B<Update docs for git #64 regarding -lp and side comments>
 
@@ -58,7 +68,7 @@ long).  For example this is ok
 
 But if a list is more than one level deep then the default indentation is used.
 
-28 Apr 2021.
+28 Apr 2021, 49977b8.
 
 =item B<Fix line break rules for uncontained commas + cleanups>
 
@@ -72,7 +82,7 @@ Other updates are: Remove unused indentation table. Correct maximum_line_length
 table for -vmll when -wc is also set.  Also fix whitespace rule for '$ ='
 within a signature to fix case b1123.
 
-26 Apr 2021.
+26 Apr 2021, d014c2a.
 
 =item B<Fix problem with -wn and -wc=n>