I did this for the last statement in an lvalue sub (and the argument
to ‘return’ in an lvalue sub) in commit
2ec7f6f2428.
It turns out that it needs to apply in other lvaluish contexts, too:
$ ./perl -Ilib -le 'for($a||$b){$_++} print $b'
1
$ ./perl -Ilib -le 'for(pos $a || pos $b){$_++} print pos $b'
Modification of a read-only value attempted at -e line 1.
If I can assign to $b through this construct, then why not pos?
case OP_AND:
case OP_OR:
- if (type == OP_LEAVESUBLV) {
- op_lvalue(cLOGOPo->op_first, type);
- op_lvalue(cLOGOPo->op_first->op_sibling, type);
- }
+ op_lvalue(cLOGOPo->op_first, type);
+ op_lvalue(cLOGOPo->op_first->op_sibling, type);
goto nomod;
}
package main;
require './test.pl';
-plan( tests => 8 );
+plan( tests => 9 );
my ($a, $b, $c);
local $TODO = 'Double FETCH';
is($c, 1, ' $tied || $var');
}
+
+$y = " ";
+for (pos $x || pos $y) {
+ eval { $_++ };
+}
+is(pos($y) || $@, 1, "|| propagates lvaluish context");