]> git.donarmstrong.com Git - perltidy.git/commitdiff
fix b1236, incorrect -kpit function with parenless for
authorSteve Hancock <perltidy@users.sourceforge.net>
Wed, 3 Nov 2021 12:49:15 +0000 (05:49 -0700)
committerSteve Hancock <perltidy@users.sourceforge.net>
Wed, 3 Nov 2021 12:49:15 +0000 (05:49 -0700)
dev-bin/run_convergence_tests.pl.data
lib/Perl/Tidy/Formatter.pm

index 6bdff02fbd33c3e5097da535918d47e0d44111ae..907df0f820dc90841cd371cc892d3817e9528e66 100644 (file)
@@ -7853,6 +7853,36 @@ $obj= {foo => sub { "bar" ; }
 --paren-vertical-tightness=1
 --weld-nested-containers
 
+==> b1236.in <==
+# Added level test when applying kpit
+# S1
+        delete $ENV{$_}
+                for
+                map {$_, uc ($_)}
+                qw/http_proxy https_proxy all_proxy/;
+
+# S2
+        delete $ENV{$_}
+                for map {
+            $_,
+                    uc ( $_ )
+                } qw/http_proxy https_proxy all_proxy/;
+
+# S3
+        delete $ENV{$_} for map {
+            $_, uc ( $_ )
+        } qw/http_proxy https_proxy all_proxy/;
+
+
+==> b1236.par <==
+--block-brace-tightness=2
+--continuation-indentation=8
+--ignore-old-breakpoints
+--keyword-paren-inner-tightness=0
+--maximum-line-length=26
+--space-keyword-paren
+--variable-maximum-line-length
+
 ==> b131.in <==
         unless
           ( open( SCORE, "+>>$Score_File" ) )
index 87a6ea365c07223e767d1c07efac502a5846b623..36653c4be3c9cef9d94e41477808506e9056a170 100644 (file)
@@ -2619,21 +2619,24 @@ sub set_whitespace_flags {
 
             elsif ( $type eq 'k' ) {
 
-              # Keywords 'for', 'foreach' are special cases for -kpit since the
-              # opening paren does not always immediately follow the keyword. So
-              # we have to search forward for the paren in this case.  I have
-              # limited the search to 10 tokens ahead, just in case somebody
-              # has a big file and no opening paren.  This should be enough for
-              # all normal code.
+                # Keywords 'for', 'foreach' are special cases for -kpit since
+                # the opening paren does not always immediately follow the
+                # keyword. So we have to search forward for the paren in this
+                # case.  I have limited the search to 10 tokens ahead, just in
+                # case somebody has a big file and no opening paren.  This
+                # should be enough for all normal code. Added the level check
+                # to fix b1236.
                 if (   $is_for_foreach{$token}
                     && %keyword_paren_inner_tightness
                     && defined( $keyword_paren_inner_tightness{$token} )
                     && $j < $jmax )
                 {
-                    my $jp = $j;
+                    my $level = $rLL->[$j]->[_LEVEL_];
+                    my $jp    = $j;
                     for ( my $inc = 1 ; $inc < 10 ; $inc++ ) {
                         $jp++;
                         last if ( $jp > $jmax );
+                        last if ( $rLL->[$jp]->[_LEVEL_] != $level );    # b1236
                         next unless ( $rLL->[$jp]->[_TOKEN_] eq '(' );
                         my $seqno_p = $rLL->[$jp]->[_TYPE_SEQUENCE_];
                         $set_container_ws_by_keyword->( $token, $seqno_p );