Perl / perl5

🐪 The Perl programming language
https://dev.perl.org/perl5/
Other
1.9k stars 540 forks source link

Add tests for lvalue subs returning vec() or substr() and called twice in one expression #22386

Closed t-a-k closed 1 month ago

t-a-k commented 2 months ago

I found that Perl prior to v5.20 (at least v5.16.3 bundled in CentOS Linux 7 and locally-built v5.18.4) fail to return correct value from subroutine returning vec() and substr() as lvalue but called multiple times in rvalue context of one expression:

$ perl -wle 'my $x = "\002"; sub myvec1 :lvalue { vec($x, $_[0], 1) }' \
    -e 'print myvec1(0); print myvec1(1); print myvec1(0) + myvec1(1)'
0
1
2
$

This apparently had been fixed in the commit 169504d53dbeb12d5171b2b44e7db3c2b81af314 (in 2013), but testcases for these symptoms doesn't seem to exist so I'd like to add ones to prevent accidental regression.

t-a-k commented 1 month ago

Could use grammer to grammar in the second commit message (which a squash would likely fix)

Sorry for the typo. I've force-pushed the second commit.