Repository navigation
mark CORE::__CLASS__ as non-ampable - #23740
Merged
Merged
Conversation
Previously: CORE::__CLASS__ and compile-time aliasing (as in `BEGIN {
*cls = \&CORE::__CLASS__; } ... cls`) worked as expected, but runtime
calls like `&CORE::__CLASS__()` and `my $ref = \&CORE::__CLASS__; ...
$ref->()` would produce bizarre results, behaving like CORE::__FILE__
instead.
Now the latter throw a "&CORE::__CLASS__ cannot be called directly"
error. This is perhaps not entirely satisfactory, but __CLASS__ is a bit
special (it is not a true constant and only usable in methods) and
erroring cleanly is better than silently returning wrong results.
Fixes Perl#23737.
Assorted changes:
- Document core_prototype()'s `opnum` parameter.
- Add comment explaining what `*opnum = 0` means (and why it makes no
sense for KEY___CLASS__).
- Don't hardcode assumptions about keyword codes in coresub_op(). Handle
__PACKAGE__/__FILE__/__LINE__ explicitly and assert() nothing else is
passed in. This effectively reverts commit c2f605d.
- Remove CORE::__CLASS__ from op/coreamp.t as it is no longer "ampable".
- Extend op/coresubs.t to handle more of the idiosyncrasies of
CORE::__CLASS__.
Rearrange documentation slightly to make it clearer what you can(not) do with CORE::chomp, CORE::chop, etc. and add CORE::__CLASS__ to the list.
coresub_op() no longer hardcodes assumptions about the numeric values of __FILE__, __LINE__, __PACKAGE__ keyword symbols.
leonerd
reviewed
Sep 20, 2025
leonerd
left a comment
Contributor
There was a problem hiding this comment.
Overall LGTM, but I'd suggest some adjustment to the perldelta.
mauke
force-pushed
the
fix-23737-amp-core-class
branch
from
September 20, 2025 14:41
c7d59f7 to
053aa58
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Previously:
CORE::__CLASS__and compile-time aliasing (as inBEGIN { *cls = \&CORE::__CLASS__; } ... cls) worked as expected, but runtime calls like&CORE::__CLASS__()andmy $ref = \&CORE::__CLASS__; ... $ref->()would produce bizarre results, behaving likeCORE::__FILE__instead.Now the latter throw a
&CORE::__CLASS__ cannot be called directlyerror. This is perhaps not entirely satisfactory, but__CLASS__is a bit special (it is not a true constant and only usable in methods) and erroring cleanly is better than silently returning wrong results.Fixes #23737.
Partially subsumes #23343.