In perl.git, the branch blead has been updated

<http://perl5.git.perl.org/perl.git/commitdiff/fe7df09eecdd7566894f43ed5bb23bdc3074e47e?hp=cbe2fc5001aa59cdc73e04cc35e097a2ecfbeec0>

- Log -----------------------------------------------------------------
commit fe7df09eecdd7566894f43ed5bb23bdc3074e47e
Author: Father Chrysostomos <spr...@cpan.org>
Date:   Thu Jan 12 22:17:04 2017 -0800

    [perl #130546] Restore delete-scalar-slice warning
    
    Commit v5.19.3-506-g429a25554a reduced false positives with the annoy-
    ing ‘Scalar value such-and-such better written as such-and-such’ warn-
    ing by flagging the op in the lexer (instead of warning immediately),
    and then checking the op tree later, in order to avoid false positives
    with perfectly valid constructs, such as qw"...".
    
    The new code that checked the op tree looked for hslice and aslice
    ops, but in the particular case of delete @a{...} and delete @a[...],
    the slice op gets nulled and the delete op takes care of the slicing
    operation (if you can call it that) itself.  The result was that the
    warning disappeared altogether for delete.
    
    This commit makes op.c check also for nulled hslice and aslice ops,
    and applies the same heuristics to them as to unnulled slicing ops.
-----------------------------------------------------------------------

Summary of changes:
 op.c              | 10 ++++++++--
 t/lib/warnings/op |  6 ++++++
 2 files changed, 14 insertions(+), 2 deletions(-)

diff --git a/op.c b/op.c
index 919e8ed514..c213bb684f 100644
--- a/op.c
+++ b/op.c
@@ -1670,10 +1670,12 @@ static void
 S_scalar_slice_warning(pTHX_ const OP *o)
 {
     OP *kid;
+    const bool h = o->op_type == OP_HSLICE
+               || (o->op_type == OP_NULL && o->op_targ == OP_HSLICE);
     const char lbrack =
-       o->op_type == OP_HSLICE ? '{' : '[';
+       h ? '{' : '[';
     const char rbrack =
-       o->op_type == OP_HSLICE ? '}' : ']';
+       h ? '}' : ']';
     SV *name;
     SV *keysv = NULL; /* just to silence compiler warnings */
     const char *key = NULL;
@@ -2596,6 +2598,10 @@ S_finalize_op(pTHX_ OP* o)
         S_check_hash_fields_and_hekify(aTHX_ rop, key_op);
        break;
     }
+    case OP_NULL:
+       if (o->op_targ != OP_HSLICE && o->op_targ != OP_ASLICE)
+           break;
+       /* FALLTHROUGH */
     case OP_ASLICE:
        S_scalar_slice_warning(aTHX_ o);
        break;
diff --git a/t/lib/warnings/op b/t/lib/warnings/op
index e8d93e8a8c..37ebbbed99 100644
--- a/t/lib/warnings/op
+++ b/t/lib/warnings/op
@@ -167,9 +167,13 @@ use warnings 'syntax' ;
 @a{--$_};
 @a[$_];
 @a[--$_];
+delete @a[$x];
+delete @a{$x};
 no warnings 'syntax' ;
 @a[3];
 @a{3};
+delete @a[$x];
+delete @a{$x};
 EXPECT
 Scalar value @a[3] better written as $a[3] at - line 3.
 Scalar value @a{3} better written as $a{3} at - line 4.
@@ -181,6 +185,8 @@ Scalar value @a{...} better written as $a{...} at - line 9.
 Scalar value @a{...} better written as $a{...} at - line 10.
 Scalar value @a[...] better written as $a[...] at - line 11.
 Scalar value @a[...] better written as $a[...] at - line 12.
+Scalar value @a[...] better written as $a[...] at - line 13.
+Scalar value @a{...} better written as $a{...} at - line 14.
 ########
 # op.c
 use utf8;

--
Perl5 Master Repository

Reply via email to