Repository navigation
Conversation
Author
|
Extended to enums: they are built after every class, so a class method returning an enum that implements the parent's return interface hit the same order dependence (tempest/highlight's |
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.
Override covariance is validated during the class-build walk, which visits classes in name order (for reproducible class ids). When the override's return type names a class that comes later in that order, that class has no
ClassInfoyet.is_subclass_of/class_implements_interfacethen answer "unrelated", and valid PHP is rejected:Renaming
EnumDefso it sorts afterEnumNodemakes the error disappear. symfony/config'sEnumNodeDefinition::instantiateNode(): EnumNodehits exactly this.pending_class_parentsalready bridges this gap for the class being built. This PR extends the same idea to classes that are only declared so far:Checker::declared_class_ancestryholds each class's declared parent and implemented interfaces, taken from the flattened declarations. It is filled right before the class walk and cleared after it, so afterwardsclassesalone answers as before.is_subclass_ofresolves parents throughparent_of, which looks at the builtClassInfo, thenpending_class_parents, then the declaration.class_implements_interfaceanswers for a class that is not built yet from its declared interfaces and those of its ancestors, including interface inheritance (interfaces are built before classes).Tests:
test_covariant_return_to_a_class_built_later(tests/codegen/oop/inheritance.rs) covers a subclass of the parent's return class and a class implementing the parent's return interface through an ancestor, both declared after the overriding class. It printsN\ZEnumNode|N\ZEnumNode|N\ZEnumNode, as php 8.5 does, and fails on main.test_error_override_return_to_unrelated_later_class(tests/error_tests/type_system.rs): an unrelated later class is still rejected.Runs:
ELEPHC_PHP_CHECK=1 cargo test --test codegen_tests inheritance: 33 passed, 1 failed. The failure isdom_html_review_generic_inheritance_injects_prelude, a local link error: the_elephc_libxml2_v1_*symbols are missing because the libxml2 native dependency isn't built here.cargo test --test codegen_tests interface: 217 passed.cargo test --test error_tests return: 68 passed.cargo test --test error_tests override: 25 passed.