]> git.donarmstrong.com Git - perltidy.git/commitdiff
Fix problem caused by side comment after ++
authorSteve Hancock <perltidy@users.sourceforge.net>
Fri, 9 Jul 2021 14:37:22 +0000 (07:37 -0700)
committerSteve Hancock <perltidy@users.sourceforge.net>
Fri, 9 Jul 2021 14:37:22 +0000 (07:37 -0700)
lib/Perl/Tidy/Tokenizer.pm
local-docs/BugLog.pod

index dae48ae29896d4971e57803d509aa05460782698..d19f7a74ba27e5790f719536e8dd32fd473135ea 100644 (file)
@@ -2928,8 +2928,17 @@ EOM
         '++' => sub {
             if    ( $expecting == TERM ) { $type = 'pp' }
             elsif ( $expecting == UNKNOWN ) {
+
                 my ( $next_nonblank_token, $i_next ) =
                   find_next_nonblank_token( $i, $rtokens, $max_token_index );
+
+                # Fix for c042: look past a side comment
+                if ( $next_nonblank_token eq '#' ) {
+                    ( $next_nonblank_token, $i_next ) =
+                      find_next_nonblank_token( $max_token_index,
+                        $rtokens, $max_token_index );
+                }
+
                 if ( $next_nonblank_token eq '$' ) { $type = 'pp' }
             }
         },
@@ -2951,6 +2960,14 @@ EOM
             elsif ( $expecting == UNKNOWN ) {
                 my ( $next_nonblank_token, $i_next ) =
                   find_next_nonblank_token( $i, $rtokens, $max_token_index );
+
+                # Fix for c042: look past a side comment
+                if ( $next_nonblank_token eq '#' ) {
+                    ( $next_nonblank_token, $i_next ) =
+                      find_next_nonblank_token( $max_token_index,
+                        $rtokens, $max_token_index );
+                }
+
                 if ( $next_nonblank_token eq '$' ) { $type = 'mm' }
             }
         },
@@ -5929,7 +5946,7 @@ sub peek_ahead_for_nonblank_token {
         }
         last;
     }
-    return $rtokens;
+    return;
 }
 
 #########i#############################################################
@@ -7643,11 +7660,14 @@ sub scan_identifier_do {
 sub find_next_nonblank_token {
     my ( $i, $rtokens, $max_token_index ) = @_;
 
+    # Returns the next nonblank token after the token at index $i
+    # To skip past a side comment, and any subsequent block comments
+    # and blank lines, call with i=$max_token_index
+
     if ( $i >= $max_token_index ) {
         if ( !peeked_ahead() ) {
             peeked_ahead(1);
-            $rtokens =
-              peek_ahead_for_nonblank_token( $rtokens, $max_token_index );
+            peek_ahead_for_nonblank_token( $rtokens, $max_token_index );
         }
     }
 
index b0b13ca559b3377ea41d5c4992333a02dfee2bd0..54e9858f79bb7a5cde6edeb932c576b9f9d7f2bf 100644 (file)
@@ -2,6 +2,23 @@
 
 =over 4
 
+=item B<Fix problem caused by side comment after ++>
+
+Testing with side comments produced an incorrect error message for this
+snippet:
+
+    xxx 
+    ++#
+    $test, 
+    Internals::SvREADONLY( %$copy) , 
+    "cloned hash restricted?" ;
+
+The problem was caused by the side comment between the '++' and '$test'.
+The same problem occurs for '--' instead of '++'.  This is fixed with this
+update, case c042.
+
+8 Jul 2021.
+
 =item B<Fix problem caused by side comment after pointer, part 2>
 
 This is related to the previous issue, c037.  The following snippet was misparsed