]> git.donarmstrong.com Git - perltidy.git/commitdiff
improve check for incorrect method call syntax, rt #145706
authorSteve Hancock <perltidy@users.sourceforge.net>
Sat, 21 Jan 2023 01:48:49 +0000 (17:48 -0800)
committerSteve Hancock <perltidy@users.sourceforge.net>
Sat, 21 Jan 2023 01:48:49 +0000 (17:48 -0800)
lib/Perl/Tidy/Tokenizer.pm
t/snippets/expect/rt145706.def
t/snippets27.t

index e50bf3495f60eb552a984911b60a2f2663ffa486..d9f641d43722fe565277399005e09bd1b63426b7 100644 (file)
@@ -2239,26 +2239,33 @@ EOM
         #    method paint => sub {
         #     ...
         #    }
+        my $next_char = EMPTY_STRING;
+        if ( $input_line =~ m/\s*(\S)/gcx ) { $next_char = $1 }
+        if ( !$next_char || $next_char eq '#' ) {
+            ( $next_char, my $i_next ) =
+              find_next_nonblank_token( $max_token_index,
+                $rtokens, $max_token_index );
+        }
 
-        if ( $input_line =~ m/\s*(\S)/gcx ) {
-            my $char = $1;
+        if ( !$next_char ) {
 
-            # Possibly valid next token types:
-            # '(' could start prototype or signature
-            # ':' could start ATTRIBUTE
-            # '{' cold start BLOCK
-            # ';' or '}' could end a statement
-            if ( $char =~ /^[\(\:\{\;\}]/ ) { return 1 }
+            # out of characters - give up
+            return;
+        }
 
-            # stop at a side comment - assume ok for now
-            if ( $char eq '#' ) { return 1 }
+        # Possibly valid next token types:
+        # '(' could start prototype or signature
+        # ':' could start ATTRIBUTE
+        # '{' cold start BLOCK
+        # ';' or '}' could end a statement
+        if ( $next_char !~ /^[\(\:\{\;\}]/ ) {
 
-            # nothing else is valid (in particular '#' and '"')
+            # This does not match use feature 'class' syntax
             return;
         }
 
-        # TBD: Still uncertain; may be at end of line
-        # We could continue will stop here and assume ok.
+        # We will stop here and assume that this is valid syntax for
+        # use feature 'class'.
         return 1;
     }
 
@@ -2312,7 +2319,11 @@ EOM
               find_next_nonblank_token( $max_token_index,
                 $rtokens, $max_token_index );
         }
-        return unless ($next_char);
+        if ( !$next_char ) {
+
+            # out of characters - give up
+            return;
+        }
 
         # Must see one of: ATTRIBUTE, VERSION, BLOCK, or end stmt
 
index 6876e31172584033e5afd605aacecb779296ee2f..28f3977c9527fa9434cefc352eaec4595596c859 100644 (file)
@@ -20,7 +20,6 @@ ADJUST {
 method paint => sub {
     ...;
 };
-
 method painter
 
   => sub {
index 7d3297020207dc7653b272e4427b990ef62aba30..0ba723b190e48dce175269bf62a0305a3769685e 100644 (file)
@@ -922,7 +922,6 @@ ADJUST {
 method paint => sub {
     ...;
 };
-
 method painter
 
   => sub {