In perl.git, the branch blead has been updated

<https://perl5.git.perl.org/perl.git/commitdiff/82de236bf4d8d37736218318628cc3f85c53ab28?hp=2fe0d7f40a94163d6c242c3e695fdcd19e387422>

- Log -----------------------------------------------------------------
commit 82de236bf4d8d37736218318628cc3f85c53ab28
Author: Tony Cook <[email protected]>
Date:   Wed May 29 14:37:25 2019 +1000

    (perl #133850) allow attributes in sub-parses

commit be9b0510216085dfb679b29a41e483c07effbb79
Author: Tony Cook <[email protected]>
Date:   Wed May 29 13:47:36 2019 +1000

    (perl #133850) allow @x{...} with space in sub-parse

commit 10724e88639b32d6d6f1024535e3f7f7aee4fb9e
Author: Tony Cook <[email protected]>
Date:   Wed May 29 11:46:01 2019 +1000

    (perl #133850) warn on ${time} even in sub-parse
    
    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.

commit eec88220688fefa843e3f46b6b454fe090ee7568
Author: Tony Cook <[email protected]>
Date:   Tue Feb 19 15:38:39 2019 +1100

    (perl #133850) fix parsing hints for print $fh "foo" in s///e
    
    The replacement code in s///e is parsed using a sublex, similarly
    to double-quotish replacement.
    
    The code that handles C< $id > tries to detect what the next token
    should be, but only special cased code similar to C< print $fh ... >
    in a non-sublex, so s/../print $fh $1/e set PL_expect to XOPERATOR
    which caused the parser to complain when the $1 wasn't an operator.
    
    The fix here handles two cases:
    
     s/.../code here/e
    
    In this case the code is inserted into a do {} block like:
    
      do { code here }
    
    so PL_lex_brackets ends up non-zero.
    
    The second case is code like:
    
      "xxx${code here}"
    
    which had the same problem, which this also fixes.

-----------------------------------------------------------------------

Summary of changes:
 t/lib/warnings/toke | 30 ++++++++++++++++++++++++++++++
 t/op/attrs.t        |  3 +++
 toke.c              |  8 ++++----
 3 files changed, 37 insertions(+), 4 deletions(-)

diff --git a/t/lib/warnings/toke b/t/lib/warnings/toke
index 83641e5106..5dbef1ab62 100644
--- a/t/lib/warnings/toke
+++ b/t/lib/warnings/toke
@@ -1691,3 +1691,33 @@ EXPECT
 OPTION regex
 Malformed UTF-8 character: .*non-continuation.*
 The eval did not crash the program
+########
+# NAME [perl #133850] print $fh $1 in s///e expression
+use warnings;
+my $fh = \*STDOUT;
+$_ = "abc";
+s/(x)/ print $fh $1 /e;
+EXPECT
+########
+# NAME [perl #133850] side case
+use warnings;
+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.
+########
+# NAME [perl #133850] another case
+use warnings;
+%x = qw(a b c d);
+$_ = "";
+s/^/ @x {a} /e
+EXPECT
+Scalar value @x{"a"} better written as $x{"a"} at - line 4.
diff --git a/t/op/attrs.t b/t/op/attrs.t
index 649525ce22..dd230b3fbd 100644
--- a/t/op/attrs.t
+++ b/t/op/attrs.t
@@ -507,4 +507,7 @@ BEGIN failed--compilation aborted at - line 1.
 EOS
               "attribute on our hash with sub of same name");
 
+fresh_perl_is('$_ = ""; s/^/ { my $x : shared = 1; } /e;', "", {},
+              "attributes in sub-parse");
+
 done_testing();
diff --git a/toke.c b/toke.c
index cecfa82378..dba907d857 100644
--- a/toke.c
+++ b/toke.c
@@ -5991,7 +5991,7 @@ Perl_yylex(pTHX)
 
        switch (PL_expect) {
        case XOPERATOR:
-           if (!PL_in_my || PL_lex_state != LEX_NORMAL)
+           if (!PL_in_my || (PL_lex_state != LEX_NORMAL && !PL_lex_brackets))
                break;
            PL_bufptr = s;      /* update in case we back off */
            if (*s == '=') {
@@ -6838,7 +6838,7 @@ Perl_yylex(pTHX)
            }
 
            PL_expect = XOPERATOR;
-           if (PL_lex_state == LEX_NORMAL && isSPACE((char)tmp)) {
+           if ((PL_lex_state == LEX_NORMAL || PL_lex_brackets) && 
isSPACE((char)tmp)) {
                const bool islop = (PL_last_lop == PL_oldoldbufptr);
                if (!islop || PL_last_lop_op == OP_GREPSTART)
                    PL_expect = XOPERATOR;
@@ -6911,7 +6911,7 @@ Perl_yylex(pTHX)
        if (!PL_tokenbuf[1]) {
            PREREF('@');
        }
-       if (PL_lex_state == LEX_NORMAL)
+       if (PL_lex_state == LEX_NORMAL || PL_lex_brackets)
            s = skipspace(s);
        if (   (PL_expect != XREF || PL_oldoldbufptr == PL_last_lop)
             && intuit_more(s, PL_bufend))
@@ -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

-- 
Perl5 Master Repository

Reply via email to