Front page | perl.perl5.porters |
Postings from January 2001
[PATCH @8545] [ID 20000808.005] OP_REFGEN as an lvalue
Thread Next
From:
Stephen McCamant
Date:
January 25, 2001 01:17
Subject:
[PATCH @8545] [ID 20000808.005] OP_REFGEN as an lvalue
Message ID:
14959.59703.507462.978833@soda.csua.berkeley.edu
While trolling for old lvalue bugs, I found the following example from
August that never seemed to be resolved (though it provoked a
B::Deparse fix, strangely enough):
AS-T> This probably shouldn't compile, but runs without complaint (and
AS-T> without any effect.)
AS-T> [D:\home\sthoenna]perl -wle "my $x; sub x:lvalue {$x}; \x = \1"
AS-T> Just for comparison:
AS-T> [D:\home\sthoenna]perl -wle "my $x; \$x = \1"
AS-T> Can't modify single ref constructor in scalar assignment at -e
AS-T> line 1, at EOF
AS-T> Execution of -e aborted due to compilation errors.
The first time I looked at it I didn't read it carefully and mistyped
the test case, making me think it was something I had fixed in a
previous lvalue patch, but on further reflection I don't think the
problem is really related to lvalue-subroutines at all -- the thing
that makes the two cases above different is that the \ in the first
example is an OP_REFGEN, while in the second it's an OP_SREFGEN.
Here's another example:
perl -e '\($x, $y) = (1, 2)'
At the moment, that's legal perl, though it doesn't do anything useful
(it creates temporary references, overwrites them with integers, and
then throws them away). I think it should instead be an error, if for
no other reason that consistency with the srefgen case. The reason
it's not an error is that mod() has a special case for OP_REFGEN,
which allows it to be in an assignment, but disables the
split-counting optimization (since \(@x) might have an arbitrarily
large number of elements just like @x could). I can't figure out the
purpose of this special case, and it seems to predate all the recorded
history of perl5 that I have easy access to (it was in 5.000). The
following patch, which removes it, passes the test suite, and makes
the example above say
Can't modify reference constructor in scalar assignment at -e line 1,
at EOF
-- Stephen "wishing for blame logs on the alpha releases" McCamant
--- op.c.orig Wed Jan 24 23:49:46 2001
+++ op.c Thu Jan 25 00:10:53 2001
@@ -1568,7 +1568,6 @@ Perl_mod(pTHX_ OP *o, I32 type)
case OP_AASSIGN:
case OP_NEXTSTATE:
case OP_DBSTATE:
- case OP_REFGEN:
case OP_CHOMP:
PL_modcount = RETURN_UNLIMITED_NUMBER;
break;
Thread Next
-
[PATCH @8545] [ID 20000808.005] OP_REFGEN as an lvalue
by Stephen McCamant