feat: support ::class on object expressions#569
Merged
Conversation
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.
Summary
receivers
make_object()::class
lookup
diagnostic
Named and scoped forms such as ClassName::class, self::class, parent::class,
and static::class keep their existing behavior.
Implementation notes
The parser keeps object-valued class-name reads structurally distinct from
compile-time ClassConstant expressions. EIR lowering evaluates the receiver
once and reuses the runtime lookup used by get_class(), so a value typed as
a base class still reports its concrete subclass.
All AST walkers, optimizer passes, name resolution, usage scans, prelude
detection, eval fallback classification, and type-analysis passes now
recurse through the new node.
The existing get_class() behavior for non-object values is intentionally
unchanged and remains tracked in #568.
Testing
cargo test --test parser_tests object_class_name
cargo test --test error_tests object_class_name
cargo test --test codegen_tests object_class_name
cargo test --lib lowers_every_expr_variant_smoke
ELEPHC_PHP_CHECK=1 cargo test --test codegen_tests
'static_class_features::test_object_class_name'
cargo build
cargo check --tests
git diff --check
Coverage includes fully-qualified runtime names, concrete subclass dispatch,
object-only unions, single receiver evaluation, and rejection of non-object
receivers.