]> git.donarmstrong.com Git - perltidy.git/commitdiff
Correct parsing error, case c061
authorSteve Hancock <perltidy@users.sourceforge.net>
Thu, 19 Aug 2021 01:13:53 +0000 (18:13 -0700)
committerSteve Hancock <perltidy@users.sourceforge.net>
Thu, 19 Aug 2021 01:13:53 +0000 (18:13 -0700)
lib/Perl/Tidy/Tokenizer.pm
local-docs/BugLog.pod

index e53381e92252f7bd96094321a321a7731fa68acf..c5f955ee97863f4fa9c1e614d21bd7a3a295f97f 100644 (file)
@@ -3507,7 +3507,25 @@ EOM
                     scan_identifier();
                 }
 
-                last if ($id_scan_state);
+                if ($id_scan_state) {
+
+                    # Still scanning ...
+                    # Check for side comment between sub and prototype (c061)
+
+                    # done if nothing left to scan on this line
+                    last if ( $i > $max_token_index );
+
+                    my ( $next_nonblank_token, $i_next ) =
+                      find_next_nonblank_token_on_this_line( $i, $rtokens,
+                        $max_token_index );
+
+                    # done if it was just some trailing space
+                    last if ( $i_next > $max_token_index );
+
+                    # something remains on the line ... must be a side comment
+                    next;
+                }
+
                 next if ( ( $i > 0 ) || $type );
 
                 # didn't find any token; start over
index 85aa5a1194a97257049d256316985c6371453c1a..e8a517ca9091d4c88e34c2af132372dcbc96c9a6 100644 (file)
@@ -2,6 +2,37 @@
 
 =over 4
 
+=item B<Correct parsing error, case c061>
+
+Testing with random input produced an error condition involving a
+side comment placed between a sub name and prototype, as in the
+following snippet:
+
+    sub
+    witch   # sc
+    ()   # prototype may be on new line ...
+    { print "which?\n" }
+    witch();
+
+The current version of perltidy makes an error:
+
+    # OLD: perltidy
+    sub witch   # sc ()    # prototype may be on new line ...
+    { print "which?\n" }
+    witch();
+
+This update corrects the problem:
+
+    # NEW: perltidy
+    sub witch    # sc
+      ()         # prototype may be on new line ...
+    { print "which?\n" }
+    witch();
+
+This fixes case c061;
+
+18 Aug 2021.
+
 =item B<Improved line break, case c060>
 
 The default formatting produced an undesirable line break at the last '&&' term