Skip to content

Commit

Permalink
add lvalue scalar alias tests to lvref.t
Browse files Browse the repository at this point in the history
This is a compile-time error:

   (\$x = \1) = \2;

However, the following is legal code, but is untested (the 'OPf_MOD'
branch in pp_refassign() is not triggered by the test suite):

   f(\$x = \1);

So this commit adds some tests. It assumes that the above code is
equivalent to:

   \$x = \1;
   f(\$x);

Whether the existing behaviour is sane is up for debate, but if
if we change it, it should be a deliberate choice, not an accidental
change not spotted by the existing tests.
  • Loading branch information
iabyn committed Nov 16, 2023
1 parent 64d8ebe commit 8b7d699
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion t/op/lvref.t
Expand Up @@ -5,7 +5,7 @@ BEGIN {
set_up_inc("../lib");
}

plan 198;
plan 201;

eval '\$x = \$y';
like $@, qr/^Experimental aliasing via reference not enabled/,
Expand Down Expand Up @@ -86,6 +86,23 @@ for (1,2) {
}
}

# Scalars in lvalue context

{
my $s = 3;
my $t = 5;

sub foo1 {
ok ref($_[0]), "foo1(alias) passes ref";
is ${$_[0]}, 5, "foo1(alias) passes ref to t";
${$_[0]} = 7;
}
foo1(\$s = \$t);
is $s, 7, "foo1(alias) passes ref to t"
}



# Array Elements

sub expect_scalar_cx { wantarray ? 0 : \$_ }
Expand Down

0 comments on commit 8b7d699

Please sign in to comment.