Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 2 commits into from
Jul 23, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 23 additions & 1 deletion t/op/sub_lval.t
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ BEGIN {
require './test.pl';
set_up_inc('../lib');
}
plan tests=>211;
plan tests=>213;

sub a : lvalue { my $a = 34; ${\(bless \$a)} } # Return a temporary
sub b : lvalue { ${\shift} }
Expand Down Expand Up @@ -1096,3 +1096,25 @@ is "@119797", "4 5 6", 'writing to array returned by bare block';
junkreturn = "b";
is($x, "b", "junkreturn");
}

# v5.18 fails to return correct value from lvalue subroutine which returns
# vec() and is called twice in rvalue context of one expression
{
my $vec = '';
sub wrap_vec : lvalue {
vec($vec, $_[0], 8);
}
wrap_vec(0) = 3;
wrap_vec(1) = wrap_vec(0) + 2;
cmp_ok(wrap_vec(0) + wrap_vec(1), '==', 8, 'wrap_vec');
}

# Ditto for returning substr()
{
my $str = 'hijk';
sub wrap_substr : lvalue {
substr($str, $_[0], 1);
}
wrap_substr(1) = 'o';
is(wrap_substr(1) . wrap_substr(3), 'ok', 'wrap_substr');
}
Loading