]> git.donarmstrong.com Git - perltidy.git/commitdiff
fix b1251, avoid new welds of sheared parens
authorSteve Hancock <perltidy@users.sourceforge.net>
Mon, 15 Nov 2021 00:23:25 +0000 (16:23 -0800)
committerSteve Hancock <perltidy@users.sourceforge.net>
Mon, 15 Nov 2021 00:23:25 +0000 (16:23 -0800)
dev-bin/run_convergence_tests.pl.data
lib/Perl/Tidy/Formatter.pm

index 9141fa4c72c5e5494490fc8ca1bb18bcc9b5fd8d..0e6a822ba52062f99ffa669186c7e9c7d9eedfa7 100644 (file)
@@ -8154,6 +8154,46 @@ WriteMakefile(
 --line-up-parentheses
 --maximum-line-length=35
 
+==> b1250.in <==
+# S1
+  @dependents=
+  (
+           split(
+             $delim,$dependent{$ctr} )
+  );
+# S2
+  @dependents=
+  (split(  $delim,$dependent{$ctr} ));
+
+==> b1250.par <==
+--noadd-whitespace
+--break-before-paren-and-indent=1
+--break-before-paren=1
+--continuation-indentation=7
+--delete-old-whitespace
+--extended-continuation-indentation
+--indent-columns=2
+--maximum-line-length=39
+--paren-vertical-tightness-closing=2
+--paren-vertical-tightness=1
+--weld-nested-containers
+
+==> b1251.in <==
+# S1
+              if (
+                     !( $line =~
+                            /\\(nonumber|(no)?tag)/ ) )
+# S2
+              if ( !($line =~ /\\(nonumber|(no)?tag)/ ) )
+
+==> b1251.par <==
+--indent-columns=7
+--maximum-line-length=57
+--paren-vertical-tightness-closing=1
+--paren-vertical-tightness=1
+--space-keyword-paren
+--weld-nested-containers
+
 ==> b1252.in <==
 # S1
 @pack=
@@ -8192,6 +8232,48 @@ WriteMakefile(
 --vertical-tightness=0
 --weld-nested-containers
 
+==> b1255.in <==
+printf
+  (
+"%-20s %-50s\n",
+    "-"
+      x 20,
+    "-"
+      x 50
+  );
+
+printf
+  (
+"%-20s %-50s\n",
+    "-" x
+         20,
+    "-"
+      x 50
+  );
+
+
+==> b1255.par <==
+--noadd-whitespace
+--ignore-old-breakpoints
+--line-up-parentheses
+--maximum-line-length=6
+--variable-maximum-line-length
+--want-break-before='x = //= > * == <= + & &= !~ x &&= !~ *= + &&='
+
+==> b1256.in <==
+# S1
+        &$out( assemble_insn(
+            $insn, $arg ) );
+# S2
+        &$out(
+            assemble_insn(
+                $insn, $arg ) );
+
+==> b1256.par <==
+--nodelete-old-newlines
+--paren-vertical-tightness-closing=2
+--weld-nested-containers
+
 ==> b131.in <==
         unless
           ( open( SCORE, "+>>$Score_File" ) )
index 242b81f38d80bd87f8a743bc62ce8a2c7c70fb94..7eff258bad450e9fe17c1eb5210f06cb86d3e301 100644 (file)
@@ -28,8 +28,8 @@
 # CODE SECTION 11: Code to break long lists
 #                  sub scan_list
 # CODE SECTION 12: Code for setting indentation
-# CODE SECTION 13: Preparing batches for vertical alignment
-#                  sub send_lines_to_vertical_aligner
+# CODE SECTION 13: Preparing batch of lines for vertical alignment
+#                  sub convey_batch_to_vertical_aligner
 # CODE SECTION 14: Code for creating closing side comments
 #                  sub add_closing_side_comment
 # CODE SECTION 15: Summarize
@@ -7342,7 +7342,7 @@ EOM
 
                     # Only save ending K indexes of code types which are blank
                     # or 'VER'.  These will be used for a convergence check.
-                    # See related code in sub 'send_lines_to_vertical_aligner'.
+                    # See related code in sub 'convey_batch_to_vertical_aligner'
                     my $CODE_type = $line_of_tokens->{_code_type};
                     if (  !$CODE_type
                         || $CODE_type eq 'VER' )
@@ -8474,6 +8474,7 @@ sub weld_nested_containers {
         my $iline_ic = $inner_closing->[_LINE_INDEX_];
         my $iline_oc = $outer_closing->[_LINE_INDEX_];
         my $token_oo = $outer_opening->[_TOKEN_];
+        my $token_io = $inner_opening->[_TOKEN_];
 
         my $is_multiline_weld =
              $iline_oo == $iline_io
@@ -8481,9 +8482,8 @@ sub weld_nested_containers {
           && $iline_io != $iline_ic;
 
         if (DEBUG_WELD) {
-            my $token_io = $rLL->[$Kinner_opening]->[_TOKEN_];
-            my $len_oo   = $rLL->[$Kouter_opening]->[_CUMULATIVE_LENGTH_];
-            my $len_io   = $rLL->[$Kinner_opening]->[_CUMULATIVE_LENGTH_];
+            my $len_oo = $rLL->[$Kouter_opening]->[_CUMULATIVE_LENGTH_];
+            my $len_io = $rLL->[$Kinner_opening]->[_CUMULATIVE_LENGTH_];
             $Msg .= <<EOM;
 Pair seqo=$outer_seqno seqi=$inner_seqno  lines: loo=$iline_oo lio=$iline_io lic=$iline_ic loc=$iline_oc
 Koo=$Kouter_opening Kio=$Kinner_opening Kic=$Kinner_closing Koc=$Kouter_closing lenoo=$len_oo lenio=$len_io
@@ -8491,6 +8491,22 @@ tokens '$token_oo' .. '$token_io'
 EOM
         }
 
+        # DO-NOT-WELD RULE 0:
+        # Avoid a new paren-paren weld if inner parens are 'sheared' (separated
+        # by one line).  This can produce instabilities (fixes b1250 b1251
+        # 1256).
+        if (  !$is_multiline_weld
+            && $iline_ic == $iline_io + 1
+            && $token_oo eq '('
+            && $token_io eq '(' )
+        {
+            if (DEBUG_WELD) {
+                $Msg .= "RULE 0: Not welding due to sheared inner parens\n";
+                print $Msg;
+            }
+            next;
+        }
+
         # If this pair is not adjacent to the previous pair (skipped or not),
         # then measure lengths from the start of line of oo.
         if (
@@ -8591,7 +8607,7 @@ EOM
                 my $excess =
                   $self->excess_line_length_for_Krange( $Kstart, $Kstop );
 
-                # Note: coding simplified here for case b1219
+                # Coding simplified here for case b1219.
                 $is_one_line_weld = $excess <= 0;
             }
 
@@ -13385,7 +13401,7 @@ EOM
             $this_batch->[_batch_count_]              = $batch_count;
             $this_batch->[_rix_seqno_controlling_ci_] = [];
 
-            $self->send_lines_to_vertical_aligner();
+            $self->convey_batch_to_vertical_aligner();
 
             my $level = $levels_to_go[$ibeg];
             $self->[_last_last_line_leading_level_] =
@@ -13850,7 +13866,7 @@ EOM
         $this_batch->[_batch_count_]              = $batch_count;
         $this_batch->[_rix_seqno_controlling_ci_] = \@ix_seqno_controlling_ci;
 
-        $self->send_lines_to_vertical_aligner();
+        $self->convey_batch_to_vertical_aligner();
 
         #-------------------------------------------------------------------
         # Write requested number of blank lines after an opening block brace
@@ -20889,9 +20905,9 @@ sub reduce_lp_indentation {
 # CODE SECTION 13: Preparing batches for vertical alignment
 ###########################################################
 
-sub check_send_lines_input {
+sub check_convey_batch_input {
 
-    # Check for valid input to sub send_lines_to_vertical_aligner.  An
+    # Check for valid input to sub convey_batch_to_vertical_aligner.  An
     # error here would most likely be due to an error in the calling
     # routine 'sub grind_batch_of_CODE'.
     my ( $self, $ri_first, $ri_last ) = @_;
@@ -20932,7 +20948,7 @@ EOM
     return;
 }
 
-sub send_lines_to_vertical_aligner {
+sub convey_batch_to_vertical_aligner {
 
     my ($self) = @_;
 
@@ -20948,7 +20964,7 @@ sub send_lines_to_vertical_aligner {
     my $ri_first   = $this_batch->[_ri_first_];
     my $ri_last    = $this_batch->[_ri_last_];
 
-    $self->check_send_lines_input( $ri_first, $ri_last ) if (DEVEL_MODE);
+    $self->check_convey_batch_input( $ri_first, $ri_last ) if (DEVEL_MODE);
 
     if ( !defined($ri_first) || !@{$ri_first} ) {