]> git.donarmstrong.com Git - perltidy.git/commitdiff
fix potential conflict of -wn -lp -pvt=2, b1338
authorSteve Hancock <perltidy@users.sourceforge.net>
Sun, 24 Apr 2022 14:01:46 +0000 (07:01 -0700)
committerSteve Hancock <perltidy@users.sourceforge.net>
Sun, 24 Apr 2022 14:01:46 +0000 (07:01 -0700)
dev-bin/run_convergence_tests.pl.data
lib/Perl/Tidy/Formatter.pm

index 81bb70cc43481b79032d8bd6651410503c719504..fe7aeeec75cc42547fba1b0ac2789b8ef0298de2 100644 (file)
@@ -9783,6 +9783,25 @@ params =>
 --maximum-line-length=19
 --variable-maximum-line-length
 
+==> b1338.in <==
+# S1:
+      (
+         sockaddr_in ( getsockname( $_[0]->[_SOCKET] ) )
+      )[0];
+
+# S2:
+      (  sockaddr_in ( getsockname( $_[0]->[_SOCKET] ) )
+      )[0];
+
+==> b1338.par <==
+--continuation-indentation=7
+--extended-line-up-parentheses
+--indent-columns=6
+--maximum-line-length=57
+--paren-vertical-tightness=2
+--space-function-paren
+--weld-nested-containers
+
 ==> b140.in <==
 $cmd[ $i ]=[
         $s, $e, $cmd, \@hunk, $i ] ;
index 79ab63b146980fc3ae4e3a1556d2a15996f4a734..f7242adc4d05e5c7603fc0fe29cb3258fd9dddca 100644 (file)
@@ -8738,6 +8738,18 @@ sub weld_nested_containers {
     my $ris_asub_block            = $self->[_ris_asub_block_];
     my $rOpts_asbl = $rOpts->{'opening-anonymous-sub-brace-on-new-line'};
 
+    # Setup hash needed for RULE 2B involving -lp -wn -vt=2
+    # Note: this could be changed in the future to include -vt=1 and -vt=2
+    # but for now only -vt=2 has caused instabilities with -wn.
+    my %no_weld_to_one_line_container;
+    if ($rOpts_line_up_parentheses) {
+        foreach ( keys %opening_vertical_tightness ) {
+            if ( $opening_vertical_tightness{$_} == 2 ) {
+                $no_weld_to_one_line_container{$_} = 1;
+            }
+        }
+    }
+
     # Find nested pairs of container tokens for any welding.
     my $rnested_pairs = $self->find_nested_pairs();
 
@@ -9137,6 +9149,19 @@ EOM
             $do_not_weld_rule = '2A';
         }
 
+        # DO-NOT-WELD RULE 2B: Turn off welding to a *one-line container for* an
+        # opening token which uses both -lp indentation and -vt=2.  See issue
+        # b1338. Also see related issue b1183 involving welds and -vt>0.
+        if (  !$do_not_weld_rule
+            && %no_weld_to_one_line_container
+            && $iline_io == $iline_ic
+            && $no_weld_to_one_line_container{$token_oo}
+            && !$rblock_type_of_seqno->{$outer_seqno}
+            && !$ris_excluded_lp_container->{$outer_seqno} )
+        {
+            $do_not_weld_rule = '2B';
+        }
+
         # DO-NOT-WELD RULE 3:
         # Do not weld if this makes our line too long.
         # Use a tolerance which depends on if the old tokens were welded