Skip to content

Improve type inference for $object::class === static::class #1761

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

Draft
wants to merge 1 commit into
base: 1.9.x
Choose a base branch
from

Conversation

rvanvelzen
Copy link
Contributor

No description provided.

@rvanvelzen rvanvelzen marked this pull request as draft September 26, 2022 12:38
Comment on lines 367 to 386
if (
$expr->left instanceof FuncCall
&& $expr->left->name instanceof Name
&& strtolower($expr->left->name->toString()) === 'get_class'
&& isset($expr->left->getArgs()[0])
&& $rightType instanceof ConstantStringType
) {
return $this->specifyTypesInCondition(
$scope,
new Instanceof_(
$expr->left->getArgs()[0]->value,
new Name($rightType->getValue()),
),
$context,
$rootExpr,
);
}
Copy link
Contributor

@staabm staabm Sep 26, 2022

Choose a reason for hiding this comment

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

fyi: I had similar stuff in #1616 - but it did not work out because of the bug I tried to fix in #1396

@rvanvelzen rvanvelzen force-pushed the static-class-const-equals branch from 5d4fc09 to 5154e11 Compare September 26, 2022 13:41
@@ -347,6 +348,59 @@ public function specifyTypesInCondition(
$rootExpr,
);
}
if (
Copy link
Contributor

Choose a reason for hiding this comment

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

if you move this block into the upper if ($expressions !== null) { block, it would work independent of operand order.

atm the code only works for if ($other::class === static::class) {, within the upper IF it would also work for if (static::class === $other::class) {

@rvanvelzen rvanvelzen changed the base branch from 1.8.x to 1.9.x October 25, 2022 13:45
@rvanvelzen rvanvelzen force-pushed the static-class-const-equals branch from 5154e11 to 8cc986c Compare October 25, 2022 13:45
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.

2 participants