summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDagfinn Ilmari Mannsåker <ilmari@ilmari.org>2021-12-10 23:57:14 +0000
committerKarl Williamson <khw@cpan.org>2021-12-16 07:56:21 -0700
commit999b4e2f823bb3637377cedf1548ce7eb27ab6c0 (patch)
tree74d0050ae573089ce28828419fa6ee4bae65ebc9
parent59f2a7f55726f30a8eb0e321563f63e1a1672258 (diff)
downloadperl-999b4e2f823bb3637377cedf1548ce7eb27ab6c0.tar.gz
Fix function calls being misinterpreted as bareword filehandles
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
-rw-r--r--t/lib/feature/bareword_filehandles9
-rw-r--r--toke.c1
2 files changed, 10 insertions, 0 deletions
diff --git a/t/lib/feature/bareword_filehandles b/t/lib/feature/bareword_filehandles
index 7eba75732c..38f8d6530c 100644
--- a/t/lib/feature/bareword_filehandles
+++ b/t/lib/feature/bareword_filehandles
@@ -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
diff --git a/toke.c b/toke.c
index 49d66e5c14..75dcee5beb 100644
--- a/toke.c
+++ b/toke.c
@@ -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);
}