Skip to content

Commit

Permalink
Fix function calls being misinterpreted as bareword filehandles
Browse files Browse the repository at this point in the history
When bareword filehandles are disabled, the parser was interpreting
any bareword as a filehandle, even when immediatey followed by parens:

    $ perl -M-feature=bareword_filehandles -le 'print foo()'
    Bareword filehandle "foo" not allowed under 'no feature "bareword_filehandles"' at -e line 1.

While with the feature enabled, it works and prints the value returned
by the function:

    $ perl  -le 'sub foo { @_ } print foo("bar")'
    bar

As for filehandles versus functions, a space before the parens makes
the difference:

    $ perl -le 'print STDOUT ("bar")'
    bar
    $ perl -le 'print STDOUT("bar")'
    Undefined subroutine &main::STDOUT called at -e line 1.

This fixes the bug by using the already-existing "immediate_paren"
variable to make it consistent when the feature is disabled.

Fixes #19271
  • Loading branch information
ilmari authored and khwilliamson committed Dec 16, 2021
1 parent 59f2a7f commit 999b4e2
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
9 changes: 9 additions & 0 deletions t/lib/feature/bareword_filehandles
Expand Up @@ -484,3 +484,12 @@ OPTIONS fatal
Bareword filehandle "FOO" not allowed under 'no feature "bareword_filehandles"' at - line 4.
Bareword filehandle "FOO" not allowed under 'no feature "bareword_filehandles"' at - line 5.
Execution of - aborted due to compilation errors.
########
# NAME subroutine calls
use feature "say";
no feature "bareword_filehandles";
sub foo {}
print foo();
say foo();
-x foo();
EXPECT
1 change: 1 addition & 0 deletions toke.c
Expand Up @@ -7620,6 +7620,7 @@ yyl_just_a_word(pTHX_ char *s, STRLEN len, I32 orig_keyword, struct code c)
s = SvPVX(PL_linestr) + s_off;

if (((PL_opargs[PL_last_lop_op] >> OASHIFT) & 7) == OA_FILEREF
&& !immediate_paren
&& !FEATURE_BAREWORD_FILEHANDLES_IS_ENABLED) {
no_bareword_filehandle(PL_tokenbuf);
}
Expand Down

0 comments on commit 999b4e2

Please sign in to comment.