This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
[perl #128260] Fix lvalue cx for substr and vec
When lvalue context was applied to the substr and vec at compile time,
that context was propagated to the first argument. That meant that
substr %foo, 1, = 3;
would correctly die, but give the wrong op in the error message, say-
ing ‘in scalar assignment’ whereas ‘in substr’ is more appropriate.
Contrariwise,
(substr %foo, 1) = 3;
would apply list lvalue context to %foo, which does not die at compile
time and prevents flattening (that’s what allows %foo=... to work).
The unflattened hash would be passed to internal functions that only
expect scalars, resulting in assertion failures.
The fix is to introduce two new types of scalar lvalue context, namely
OP_SUBSTR and OP_VEC, and apply those to the first argument, causing
both the examples above to die at compile time with ‘Can't modify hash
dereference in substr’.
If the surrounding context is only potential modifiable context (such
as \substr), then that same non-fatal context is applied to the
first argument.