Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This is perhaps not ideal, but it fixes (or allows to be fixed) seve- ral bugs. I was hoping that the cases that this perhaps erroneously allows through would fall back to the warning I added in commit 8fe85e3, but, unfortunately, in all these cases the refcount is greater than 1 when pp_sassign is reached. To be less vague: ‘foo() = 3’ warns if foo() returns a TEMP with no set-magic and a refcount of 1 (meaning it will be freed shortly). But truly temporary values returned by pure-Perl lvalue subs have a refer- ence count of at least 2, and as many entries on the mortals stack. I cannot distinguish between truly temporary values and those that are but nominally temporary (marked TEMP because the refcount will go down, but not to zero) by checking for a refcount <= 2 in pp_sassign, because this example returns with a refcount of 2: +sub :lvalue { return delete($_[0]), $x }->($x) = 3; # returns a TEMP There’s no logical reason why that shouldn’t work, if this does: +sub :lvalue { return foo(), $x }->($x) = 3; # not TEMP as they are conceptually identical. The advantages to this change: • The delete example above will work. • It allows XS lvalue subs that return TEMPs to work in the debugger [perl #71172], restoring the bug fix that b724cc1 implemented but c73030b reverted. • It makes these three cases identical, as they should be. Note that only two of them return TEMPs: +sub :lvalue { return shift }->($x) = 3; +sub :lvalue { \@_; return shift }->($x) = 3; # returns a TEMP +sub :lvalue { return delete $_[0] }->($x) = 3; # returns a TEMP So I think the advantages outweigh the disadvantages.
- Loading branch information