Don't crash on constants that reference themselves#2984
Merged
dantleech merged 2 commits intophpactor:masterfrom Dec 20, 2025
Merged
Don't crash on constants that reference themselves#2984dantleech merged 2 commits intophpactor:masterfrom
dantleech merged 2 commits intophpactor:masterfrom
Conversation
5841394 to
92e8af7
Compare
92e8af7 to
92fa96e
Compare
dantleech
reviewed
Dec 18, 2025
| assertion: function (Diagnostics $diagnostics): void { | ||
| Assert::assertCount(0, $diagnostics); | ||
| } | ||
| ); |
Collaborator
There was a problem hiding this comment.
why is this here - i.e. there is no diagnostic for this (and I don't think it makes sense to have one)? if fr testing can it be a file in lib/WorseReflection/Tests/Inference/reflection/self-referencing-cnstant.test instead?
Contributor
Author
There was a problem hiding this comment.
I didn't know where to put it, the class that caused the infinite loop in the example was the diagnostic provider. But yeah just checking for any reflection errors should be enough.
Collaborator
|
ta |
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.
Fixes #2982
Implementation details
This is currently only solved for the case of a class constant. Maybe we could unifiy this with how variables work in phpactor because
$a = $adoesn't crash.If a constant assigns itself, then we assume
mixedtype (any guess is fine).Remaining problems
The code doesn't work, maybe we should also add a diagnostic that disallows this kind of code. Even if you try to declare a const in a subclass of the abstract class, php crashes with "can't override a constant"
You can still run the NodeContextResolver into an infinite loop, maybe we could have some kind of protection against that.