fix instabilities b1274 b1275 involving combo -bbx=2 -lp or -vmll
authorSteve Hancock <perltidy@users.sourceforge.net>
Fri, 7 Jan 2022 14:49:05 +0000 (06:49 -0800)
committerSteve Hancock <perltidy@users.sourceforge.net>
Fri, 7 Jan 2022 14:49:05 +0000 (06:49 -0800)
dev-bin/run_convergence_tests.pl.data
lib/Perl/Tidy/Formatter.pm

index 74556436ea417a112f07f59efdef8fde01ea53d3..5486876370512a5315a91d9962869e7f6e89c79d 100644 (file)
@@ -8605,6 +8605,78 @@ use overload
 --keyword-paren-inner-tightness=2
 --maximum-line-length=56
 
+==> b1274.in <==
+# S1
+       $$d{"month_abb"} = [
+                          [
+                            "Jan", "Feb", "Mar", "Apr",
+                            "Maj", "Jun", "Jul", "Aug",
+                            "Sep", "Okt", "Nov", "Dec"
+                          ]
+       ];
+# S2
+       $$d{"month_abb"} =
+       [
+          [
+             "Jan", "Feb", "Mar", "Apr", "Maj", "Jun",
+             "Jul", "Aug", "Sep", "Okt", "Nov", "Dec"
+          ]
+       ];
+
+# S3
+       $$d{"month_abb"} = [
+            [
+              "Jan", "Feb", "Mar", "Apr", "Maj", "Jun",
+              "Jul", "Aug", "Sep", "Okt", "Nov", "Dec"
+            ]
+       ];
+
+
+
+==> b1274.par <==
+--break-before-square-bracket=2
+--continuation-indentation=0
+--extended-line-up-parentheses
+--ignore-old-breakpoints
+--indent-columns=7
+--maximum-line-length=56
+
+==> b1275.in <==
+    $$d{"month_abb"} = [
+           [
+               "sty.", "lut.", "mar.", "kwi.", "maj", "cze.", "lip.", "sie.", "wrz.", "paz.", "lis.", "gru."
+           ], [
+               "sty.", "lut.", "mar.", "kwi.", "maj", "cze.", "lip.", "sie.", "wrz.", "pa\9f.", "lis.", "gru."
+           ]
+       ];
+
+    $$d{"month_abb"} = [
+        [ "sty.", "lut.", "mar.", "kwi.", "maj", "cze.", "lip.", "sie.", "wrz.", "paz.", "lis.", "gru." ],
+        [ "sty.", "lut.", "mar.", "kwi.", "maj", "cze.", "lip.", "sie.", "wrz.", "pa\9f.", "lis.", "gru." ]
+    ];
+
+==> b1275.par <==
+--break-before-square-bracket=2
+--continuation-indentation=3
+--extended-continuation-indentation
+--maximum-line-length=100
+--opening-square-bracket-right
+--nostack-closing-block-brace
+--nostack-closing-hash-brace
+--nostack-closing-paren
+--nostack-closing-square-bracket
+--nostack-opening-hash-brace
+--nostack-opening-paren
+--nostack-opening-square-bracket
+--nostatic-block-comments
+--notight-secret-operators
+--notrim-pod
+--use-unicode-gcstring
+--novalign-side-comments
+--variable-maximum-line-length
+--vertical-tightness-closing=0
+--vertical-tightness=0
+
 ==> b1277.in <==
 # S1
           match_on_type @_ => Null => sub { [] },
index 8d7a6145ddcbbf5d72d28f11da4391318b9d0c2e..f8bbb90748aeeb6cc0abf6a87085ea66e1fd1341 100644 (file)
@@ -9825,6 +9825,59 @@ sub break_before_list_opening_containers {
 
         my $ci = $rLL->[$KK]->[_CI_LEVEL_];
 
+        #--------------------------------------------
+        # New coding for option 2 (break if complex).
+        #--------------------------------------------
+        # This new coding uses clues which are invariant under formatting to
+        # decide if a list is complex.  For now it is only applied when -lp
+        # and -vmll are used, but eventually it may become the standard method.
+        # Fixes b1274, b1275, and others, including b1099.
+        if ( $break_option == 2 ) {
+
+            if (   $rOpts_line_up_parentheses
+                || $rOpts_variable_maximum_line_length )
+            {
+
+                # Start with the basic definition of a complex list...
+                my $is_complex = $is_list && $has_list;
+
+                # and it is also complex if the parent is a list
+                if ( !$is_complex ) {
+                    my $parent = $rparent_of_seqno->{$seqno};
+                    if ( $self->is_list_by_seqno($parent) ) {
+                        $is_complex = 1;
+                    }
+                }
+
+                # finally, we will call it complex if there are inner opening
+                # and closing container tokens within the outer container
+                # tokens.
+                if ( !$is_complex ) {
+                    my $Kp     = $self->K_next_nonblank($KK);
+                    my $type_p = defined($Kp) ? $rLL->[$Kp]->[_TYPE_] : 'b';
+                    if ( $is_opening_type{$type_p} ) {
+
+                        my $Kc     = $K_closing_container->{$seqno};
+                        my $Km     = $self->K_previous_nonblank($Kc);
+                        my $type_m = defined($Km) ? $rLL->[$Km]->[_TYPE_] : 'b';
+
+                        # ignore any optional ending comma
+                        if ( $type_m eq ',' ) {
+                            $Km = $self->K_previous_nonblank($Km);
+                            $type_m =
+                              defined($Km) ? $rLL->[$Km]->[_TYPE_] : 'b';
+                        }
+
+                        $is_complex ||= $is_closing_type{$type_m};
+                    }
+                }
+
+                # Convert to option 3 (always break) if complex
+                next unless ($is_complex);
+                $break_option = 3;
+            }
+        }
+
         # Fix for b1231: the has_list_with_lec does not cover all cases.
         # A broken container containing a list and with line-ending commas
         # will stay broken, so can be treated as if it had a list with lec.
@@ -9874,15 +9927,6 @@ sub break_before_list_opening_containers {
                 }
             }
 
-            # 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 ) {
-                if ( $is_list && $has_list ) {
-                    $ok_to_break = 1;
-                    DEBUG_BBX && do { $Msg = "is list or has list" };
-                }
-            }
-
             if ( !$ok_to_break ) {
                 DEBUG_BBX
                   && print STDOUT "Not breaking at seqno=$seqno: $Msg\n";