This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
(perl #133850) warn on ${time} even in sub-parse
authorTony Cook <tony@develop-help.com>
Wed, 29 May 2019 01:46:01 +0000 (11:46 +1000)
committerTony Cook <tony@develop-help.com>
Tue, 11 Jun 2019 06:08:36 +0000 (16:08 +1000)
Code like:

  $a = ${time}

warns with:

  Ambiguous use of ${time} resolved to $time at ...

but:

  s/^/ ${time} /e

didn't, since the parser is in a special state in sub-parses.

t/lib/warnings/toke
toke.c

index 944e5d9..eab22fb 100644 (file)
@@ -1705,3 +1705,11 @@ my $fh = \*STDOUT;
 my $y = "";
 my $x = "${print $fh $y; \'x'}";
 EXPECT
+########
+# NAME [perl #133850] another case
+use warnings;
+my $time = 1;
+$_ = "";
+s/^/ ${time} /e
+EXPECT
+Ambiguous use of ${time} resolved to $time at - line 4.
diff --git a/toke.c b/toke.c
index f3b643c..c3390c2 100644 (file)
--- a/toke.c
+++ b/toke.c
@@ -9660,7 +9660,7 @@ S_scan_ident(pTHX_ char *s, char *dest, STRLEN destlen, I32 ck_uni)
                PL_lex_state = LEX_INTERPEND;
                PL_expect = XREF;
            }
-           if (PL_lex_state == LEX_NORMAL) {
+           if (PL_lex_state == LEX_NORMAL || PL_lex_brackets) {
                if (ckWARN(WARN_AMBIGUOUS)
                     && (keyword(dest, d - dest, 0)
                        || get_cvn_flags(dest, d - dest, is_utf8