This is a regression in 5.14.0.
Commit
6f1401dc made ops call get-magic before overloading, but it
ended up making filetest ops call get-magic on the topmost item of the
stack even if the filetest op was not going to use the stack (which
happens for ‘-r bareword’ and plain ‘-r’).
This would affect cases like:
push @foo, $tied, -r;
#define tryAMAGICftest_MG(chr) STMT_START { \
if ( (SvFLAGS(TOPs) & (SVf_ROK|SVs_GMG)) \
+ && PL_op->op_flags & OPf_KIDS \
&& S_try_amagic_ftest(aTHX_ chr)) \
return NORMAL; \
} STMT_END
assert(chr != '?');
SvGETMAGIC(arg);
- if ((PL_op->op_flags & OPf_KIDS)
- && SvAMAGIC(TOPs))
+ if (SvAMAGIC(TOPs))
{
const char tmpchr = chr;
SV * const tmpsv = amagic_call(arg,
}
use Config;
-plan(tests => 29 + 27*14);
+plan(tests => 30 + 27*14);
ok( -d 'op' );
ok( -f 'TEST' );
push my @foo, "bar", -l baz;
is $foo[0], "bar", '-l bareword does not corrupt the stack';
}
+
+# File test ops should not call get-magic on the topmost SV on the stack if
+# it belongs to another op.
+{
+ my $w;
+ sub oon::TIESCALAR{bless[],'oon'}
+ sub oon::FETCH{$w++}
+ tie my $t, 'oon';
+ push my @a, $t, -t;
+ is $w, 1, 'file test does not call FETCH on stack item not its own';
+}