From: Steve Hancock Date: Mon, 13 Sep 2021 15:22:55 +0000 (-0700) Subject: Fix unusual parsing error b1205 X-Git-Tag: 20210717.03~10 X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=cfa2515a69196ed7d16bcd679eb62e70713b049c;p=perltidy.git Fix unusual parsing error b1205 --- diff --git a/lib/Perl/Tidy/Tokenizer.pm b/lib/Perl/Tidy/Tokenizer.pm index b6fb1c8e..ad1982d6 100644 --- a/lib/Perl/Tidy/Tokenizer.pm +++ b/lib/Perl/Tidy/Tokenizer.pm @@ -5391,6 +5391,13 @@ sub operator_expected { $op_expected = UNKNOWN; } + # Exception to weird parsing rules for 'x(' ... see case b1205: + # In something like 'print $vv x(...' the x is an operator; + # otherwise x follows the weird parsing rules. + elsif ( $tok eq 'x' && $next_type eq '(' ) { + $op_expected = OPERATOR; + } + # The 'weird parsing rules' of next section do not work for '<' and '?' # It is best to mark them as unknown. Test case: # print $fh ; diff --git a/local-docs/BugLog.pod b/local-docs/BugLog.pod index 7e1a5845..16a02cea 100644 --- a/local-docs/BugLog.pod +++ b/local-docs/BugLog.pod @@ -2,6 +2,28 @@ =over 4 +=item B + +Testing with random parameters produced an instability caused by misparsing +an 'x' operator after a possible file handle. Testing with Perl showed that +an 'x' followed by a '(' in this location is always the 'times' operator and +never a call to a function 'x'. If x is immediately followed by a number it +is subject to the usual weird parsing rules at such a location. + +To illustrate, consider what these statements do: + + open( my $zz, ">", "junk.txt" ); + sub x { return $_[0] } # never called + print $zz x(2); # prints a glob 2 times; not a function call + print $zz x 2; # prints a glob 2 times + print $zz x2; # syntax error + print $zz x; # syntax error + print $zz z; # prints 'z' in file 'junk.txt' + +This update fixes case b1205. + +13 Sep 2021. + =item B Testing with random input parameters produced a number of cases of unstable