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
authorFather Chrysostomos <sprout@cpan.org>
Sat, 11 Jun 2016 01:08:50 +0000 (18:08 -0700)
committerFather Chrysostomos <sprout@cpan.org>
Sat, 11 Jun 2016 13:17:01 +0000 (06:17 -0700)
commit79409ac8354d04a53c3ba700bc429df2d9bd2043
tree76814f549443af3915802134d717c88e7a341e7c
parent1a3e97240d9aa40adfeecbebce3f3cce94fe131b
[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.
op.c
t/lib/croak/op