Skip to content

Fix MixedType->equals(ErrorType) #3934

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 13 commits into
base: 2.1.x
Choose a base branch
from
Open

Fix MixedType->equals(ErrorType) #3934

wants to merge 13 commits into from

Conversation

staabm
Copy link
Contributor

@staabm staabm commented Apr 13, 2025

@staabm
Copy link
Contributor Author

staabm commented Apr 13, 2025

I was not sure whether TemplateMixedType should be considered equal to MixedType or not

@staabm staabm marked this pull request as draft April 13, 2025 20:37
@staabm staabm marked this pull request as ready for review April 14, 2025 07:45
@phpstan-bot
Copy link
Collaborator

This pull request has been marked as ready for review.

@herndlm
Copy link
Contributor

herndlm commented Apr 14, 2025

👍 I suppose this improves the weird cases I had before too, where error is accepted as a mixed or at least something like that 😊

@@ -4489,7 +4489,7 @@ public function addTypeToExpression(Expr $expr, Type $type): self

if ($originalExprType->equals($nativeType)) {
$newType = TypeCombinator::intersect($type, $originalExprType);
if ($newType->isConstantScalarValue()->yes() && $newType->equals($originalExprType)) {
if ($newType->isObject()->no() && $newType->equals($originalExprType)) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will look into whether we can get rid of the isObject() check here today

Copy link
Contributor Author

@staabm staabm May 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, I looked into it. I think we cannot drop the $newType->isObject()->no() check here, because Objects will be considered equal by ObjectType->equals() even though they have slight differences which are important when narrowing, e.g.

new Foo() in local-scope vs. Foo typed variable (implicit Final)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

most conservative move would be to leave it $newType->isConstantScalarValue()->yes() until we get a slow case which benefits from the change and only fix MixedType->equals(ErrorType) for now

@clxmstaab clxmstaab force-pushed the equals branch 2 times, most recently from 868ed2e to 65df00a Compare May 14, 2025 11:58
@staabm
Copy link
Contributor Author

staabm commented May 16, 2025

just reduced it to the actual bugfix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants