]> git.donarmstrong.com Git - perltidy.git/commitdiff
Fix unusual parsing error b1205
authorSteve Hancock <perltidy@users.sourceforge.net>
Mon, 13 Sep 2021 15:22:55 +0000 (08:22 -0700)
committerSteve Hancock <perltidy@users.sourceforge.net>
Mon, 13 Sep 2021 15:22:55 +0000 (08:22 -0700)
lib/Perl/Tidy/Tokenizer.pm
local-docs/BugLog.pod

index b6fb1c8e1df9c178ac09bf6be1ea548cc73e6bb0..ad1982d65bf8f0bf66f59056daa3e5f243efffe7 100644 (file)
@@ -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 <DATA>;
index 7e1a5845612ddb74296e2cd293fad517d4bf97ad..16a02ceadb2149e3cfb052533f51fe93ee785676 100644 (file)
@@ -2,6 +2,28 @@
 
 =over 4
 
+=item B<Fix unusual parsing error b1205>
+
+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<Use stress_level to fix cases b1197-b1204>
 
 Testing with random input parameters produced a number of cases of unstable