Skip to content

Commit

Permalink
Make scalar() propagate lvalueness
Browse files Browse the repository at this point in the history
As mentioned in ticket #24346, scalar() should not change lvalueness.
The fact that it did was a side effect of the implementation and a
bug.  foo(scalar substr(....)) should pass a substr lvalue to foo just
as it would without scalar() or with a $ prototype (which is meant to
be equivalent to scalar()).

This also makes it possible to force scalar context in list assignment
to lvalue subroutines, as in (foo(), scalar bar()) = @list.
  • Loading branch information
Father Chrysostomos committed Dec 13, 2011
1 parent 6d91e95 commit d408447
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
1 change: 1 addition & 0 deletions op.c
Expand Up @@ -2001,6 +2001,7 @@ Perl_op_lvalue_flags(pTHX_ OP *o, I32 type, U32 flags)
else if (!(o->op_flags & OPf_KIDS))
break;
if (o->op_targ != OP_LIST) {
case OP_SCALAR:
op_lvalue(cBINOPo->op_first, type);
break;
}
Expand Down
9 changes: 8 additions & 1 deletion t/op/substr.t
Expand Up @@ -23,7 +23,7 @@ $SIG{__WARN__} = sub {

BEGIN { require './test.pl'; }

plan(381);
plan(382);

run_tests() unless caller;

Expand Down Expand Up @@ -684,6 +684,13 @@ is($x, "\x{100}\x{200}\xFFb");
}
}

# Also part of perl #24346; scalar(substr...) should not affect lvalueness
{
my $str = "abcdef";
sub { $_[0] = 'dea' }->( scalar substr $str, 3, 2 );
is $str, 'abcdeaf', 'scalar does not affect lvalueness of substr';
}

# [perl #24200] string corruption with lvalue sub

{
Expand Down

0 comments on commit d408447

Please sign in to comment.