The code path that looks up ‘our’ subs was not vivifying GVs in
the symbol table, and it was assuming that anything it found
would be a GV.
Constants created by ‘use constant’ are stored as simple scalar refs,
when possible, instead of GVs with CVs.
So GvCV() was called on an RV, and blew up.
$ ./miniperl -Ilib -Mfeature=lexical_subs -e 'our sub foo; BEGIN { delete $::{foo}; } use constant foo=>3; warn foo()'
The lexical_subs feature is experimental at -e line 1.
Assertion failed: (SvTYPE(_gvgp) == SVt_PVGV || SvTYPE(_gvgp) == SVt_PVLV), function Perl_yylex, file toke.c, line 6566.
Abort trap: 6
*bar::is = *is;
*bar::like = *like;
}
-plan 129;
+plan 130;
# -------------------- Errors with feature disabled -------------------- #
my $y = if if if;
is $y, 42, 'our subs from other packages override all keywords';
}
+# Interaction with ‘use constant’
+{
+ our sub const; # symtab now has an undefined CV
+ BEGIN { delete $::{const} } # delete symtab entry; pad entry still exists
+ use constant const => 3; # symtab now has a scalar ref
+ # inlining this used to fail an assertion (parentheses necessary):
+ is(const, 3, 'our sub pointing to "use constant" constant');
+}
# -------------------- state -------------------- #
rv2cv_op =
newCVREF(OPpMAY_RETURN_CONSTANT<<8, const_op);
cv = lex
- ? GvCV(gv)
+ ? isGV(gv) ? GvCV(gv) : (CV *)gv
: rv2cv_op_cv(rv2cv_op, RV2CVOPCV_RETURN_STUB);
}