]> git.donarmstrong.com Git - perltidy.git/commitdiff
fix b1413, b1415
authorSteve Hancock <perltidy@users.sourceforge.net>
Sun, 30 Oct 2022 14:49:26 +0000 (07:49 -0700)
committerSteve Hancock <perltidy@users.sourceforge.net>
Sun, 30 Oct 2022 14:49:26 +0000 (07:49 -0700)
dev-bin/run_convergence_tests.pl.data
lib/Perl/Tidy/Formatter.pm

index e77ac768315c39582b62657d14d99a435b72d5b2..c5aaa464c885f88e74d7fdf63eb5b88b59af0103 100644 (file)
@@ -10694,6 +10694,58 @@ my %MyTokens= (
 --maximum-line-length=66
 --noadd-whitespace
 
+==> b1413.in <==
+    &PDL::_conv2d_int(
+        $a, $kern, $c,
+        (  !(  defined $opt
+               && exists $$opt{Boundary} )
+        ) ? 0 : (
+            ( $$opt{Boundary} eq "Reflect"
+            ) + 2 * ( $$opt{Boundary} eq "Truncate" )
+        )
+    );
+
+    &PDL::_conv2d_int(
+        $a, $kern, $c,
+        (
+           !(  defined $opt
+               && exists $$opt{Boundary} )
+        ) ? 0 : (
+            ( $$opt{Boundary} eq "Reflect"
+            ) + 2 * ( $$opt{Boundary} eq "Truncate" )
+        )
+    );
+
+==> b1413.par <==
+--delete-old-whitespace
+--keep-old-breakpoints-before=') &&'
+--line-up-parentheses
+--variable-maximum-line-length
+--vertical-tightness=2
+--weld-nested-containers
+
+==> b1415.in <==
+if (
+     ioctl( STDERR, $TIOCGWINSZ,
+            $winsize )
+  )
+{
+    ...;
+}
+
+if ( ioctl( STDERR, $TIOCGWINSZ,
+            $winsize )
+  )
+{
+    ...;
+}
+
+==> b1415.par <==
+--extended-line-up-parentheses
+--maximum-line-length=39
+--paren-vertical-tightness=2
+--weld-nested-containers
+
 ==> b146.in <==
 # State 1
 
index 4b88f2eb151bef222343320e32722cc11f4020fd..721a7dec346b7c147b53b1c6aea12b176d7c7d69 100644 (file)
@@ -532,7 +532,7 @@ BEGIN {
         _ris_bare_trailing_comma_by_seqno_ => $i++,
 
         _rseqno_non_indenting_brace_by_ix_ => $i++,
-        _rzero_vertical_tightness_         => $i++,
+        _rmax_vertical_tightness_          => $i++,
 
         _no_vertical_tightness_flags_ => $i++,
 
@@ -955,7 +955,7 @@ sub new {
     $self->[_ris_bare_trailing_comma_by_seqno_] = {};
 
     $self->[_rseqno_non_indenting_brace_by_ix_] = {};
-    $self->[_rzero_vertical_tightness_]         = {};
+    $self->[_rmax_vertical_tightness_]          = {};
 
     $self->[_no_vertical_tightness_flags_] = 0;
 
@@ -9805,7 +9805,7 @@ sub weld_nested_containers {
     my $rblock_type_of_seqno      = $self->[_rblock_type_of_seqno_];
     my $ris_excluded_lp_container = $self->[_ris_excluded_lp_container_];
     my $ris_asub_block            = $self->[_ris_asub_block_];
-    my $rzero_vertical_tightness  = $self->[_rzero_vertical_tightness_];
+    my $rmax_vertical_tightness   = $self->[_rmax_vertical_tightness_];
 
     my $rOpts_asbl = $rOpts->{'opening-anonymous-sub-brace-on-new-line'};
 
@@ -9819,6 +9819,23 @@ sub weld_nested_containers {
     # pairs.  But it isn't clear if this is possible because we don't know
     # which sequences might actually start a weld.
 
+    # To avoid instabilities with combination -lp -wn -pvt=2, reduce -vt=2 to
+    # -vt=1 where there could be a conflict with welding at the same tokens.
+    # See issues b1338, b1339, b1340, b1341, b1342, b1343, b1415.
+    if ($rOpts_line_up_parentheses) {
+
+        # NOTE: this has only been found to be necessary for parens, but this
+        # could be applied to all types if necessary.
+        if ( $opening_vertical_tightness{'('} == 2 ) {
+            foreach my $item ( @{$rnested_pairs} ) {
+                my ( $inner_seqno, $outer_seqno ) = @{$item};
+                if ( !$ris_excluded_lp_container->{$outer_seqno} ) {
+                    $rmax_vertical_tightness->{$outer_seqno} = 1;
+                }
+            }
+        }
+    }
+
     my $rOpts_break_at_old_method_breakpoints =
       $rOpts->{'break-at-old-method-breakpoints'};
 
@@ -9943,14 +9960,16 @@ sub weld_nested_containers {
         my $token_oo = $outer_opening->[_TOKEN_];
         my $token_io = $inner_opening->[_TOKEN_];
 
-        # Turn off vertical tightness at possible one-line welds.
-        # Fixes b1402.  Also replaces a previous patch for
-        # issues b1338, b1339, b1340, b1341, b1342, b1343.
+        # Turn off vertical tightness completely at possible one-line welds.
+        # Fixes b1402.  This also fixes issues b1338, b1339, b1340, b1341,
+        # b1342, b1343, but both fixes are needed in general for good
+        # protection against instability.  The line difference of '2'
+        # works but could be increased if necessary.
         if (   %opening_vertical_tightness
             && $opening_vertical_tightness{$token_oo} )
         {
             if ( $iline_oc - $iline_oo <= 2 ) {
-                $rzero_vertical_tightness->{$outer_seqno} = 1;
+                $rmax_vertical_tightness->{$outer_seqno} = 0;
             }
         }
 
@@ -27476,17 +27495,19 @@ sub set_vertical_tightness_flags {
 
            # The flag '_rwant_container_open_' avoids conflict of -bom and -pt=1
            # or -pt=2; fixes b1270. See similar patch above for $cvt.
-           # The flag '_rzero_vertical_tightness_' avoids welding conflicts.
             my $seqno = $type_sequence_to_go[$iend];
-            if (
-                $ovt
-                && (   $self->[_rwant_container_open_]->{$seqno}
-                    || $self->[_rzero_vertical_tightness_]->{$seqno} )
-              )
+            if (   $ovt
+                && $self->[_rwant_container_open_]->{$seqno} )
             {
                 $ovt = 0;
             }
 
+            # The flag '_rmax_vertical_tightness_' avoids welding conflicts.
+            if ( defined( $self->[_rmax_vertical_tightness_]->{$seqno} ) ) {
+                $ovt =
+                  min( $ovt, $self->[_rmax_vertical_tightness_]->{$seqno} );
+            }
+
             unless (
                 $ovt < 2
                 && ( $nesting_depth_to_go[ $iend_next + 1 ] !=