From: Steve Hancock Date: Sat, 21 Jan 2023 01:48:49 +0000 (-0800) Subject: improve check for incorrect method call syntax, rt #145706 X-Git-Tag: 20221112.04~8 X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=69124c09d6547af09daaba0848b0c4866b729e40;p=perltidy.git improve check for incorrect method call syntax, rt #145706 --- diff --git a/lib/Perl/Tidy/Tokenizer.pm b/lib/Perl/Tidy/Tokenizer.pm index e50bf349..d9f641d4 100644 --- a/lib/Perl/Tidy/Tokenizer.pm +++ b/lib/Perl/Tidy/Tokenizer.pm @@ -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 diff --git a/t/snippets/expect/rt145706.def b/t/snippets/expect/rt145706.def index 6876e311..28f3977c 100644 --- a/t/snippets/expect/rt145706.def +++ b/t/snippets/expect/rt145706.def @@ -20,7 +20,6 @@ ADJUST { method paint => sub { ...; }; - method painter => sub { diff --git a/t/snippets27.t b/t/snippets27.t index 7d329702..0ba723b1 100644 --- a/t/snippets27.t +++ b/t/snippets27.t @@ -922,7 +922,6 @@ ADJUST { method paint => sub { ...; }; - method painter => sub {