This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
[perl #128260] Fix \substr %h
[perl5.git] / op.c
diff --git a/op.c b/op.c
index be6e7b7..8008a21 100644 (file)
--- a/op.c
+++ b/op.c
@@ -3062,11 +3062,14 @@ Perl_op_lvalue_flags(pTHX_ OP *o, I32 type, U32 flags)
        if (o->op_flags & OPf_KIDS && OpHAS_SIBLING(cBINOPo->op_first)) {
            /* substr and vec */
            /* If this op is in merely potential (non-fatal) modifiable
-              context, then propagate that context to the kid op.  Other-
+              context, then apply OP_ENTERSUB context to
+              the kid op (to avoid croaking).  Other-
               wise pass this op’s own type so the correct op is mentioned
               in error messages.  */
            op_lvalue(OpSIBLING(cBINOPo->op_first),
-                     S_potential_mod_type(type) ? type : o->op_type);
+                     S_potential_mod_type(type)
+                       ? OP_ENTERSUB
+                       : o->op_type);
        }
        break;