Come for the quick hacks, stay for the epiphanies. | |
PerlMonks |
Re: When aliasing sub arguments to @_ elements, PADTMP, READONLY flags are copied inconsistentlyby ikegami (Patriarch) |
on Jan 20, 2020 at 16:16 UTC ( [id://11111637]=note: print w/replies, xml ) | Need Help?? |
$_[0] is not a copy. It's literally the same scalar that was passed as an argument. That means the first 1+1 produced a read-only scalar and the second one didn't. We can see some differences in the generated code.
So it appears that a folded constant (FOLD) in lvalue context (M) returns a writable scalar. We can also see the difference when using the referencing operator or foreach, as they also also impose an lvalue context.
I believe this is intentional. Addition normally produces a writable scalar, and those semantics are being preserved even when the operands of the addition are constants.
In Section
Seekers of Perl Wisdom
|
|