Skip to content
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

improve is_subclass_of type checks #1321

Merged
merged 12 commits into from
May 17, 2022
Merged

Conversation

staabm
Copy link
Contributor

@staabm staabm commented May 16, 2022

@@ -2,7 +2,15 @@

/**
* @param ($allow_string is false ? object : object|string) $object_or_class
* @param class-string $class
Copy link
Contributor Author

@staabm staabm May 16, 2022

Choose a reason for hiding this comment

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

changed both, is_a and is_subclass_of $class arg back to string for max compat with 1.6.x

@@ -42,6 +43,11 @@ public function specifyTypes(FunctionReflection $functionReflection, FuncCall $n
$allowStringType = isset($node->getArgs()[2]) ? $scope->getType($node->getArgs()[2]->value) : new ConstantBooleanType(true);
$allowString = !$allowStringType->equals(new ConstantBooleanType(false));

// prevent false-positives in IsAFunctionTypeSpecifyingHelper
if ($objectOrClassType instanceof GenericClassStringType && $classType instanceof GenericClassStringType) {
Copy link
Contributor Author

@staabm staabm May 16, 2022

Choose a reason for hiding this comment

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

obviously this is not a great fix, but with this PR we fix the existing/reported false-positives.
proper support for generic-class-string in is_subclass_of could be added later.. since there are not existing tests for this case, this should be fine for now

@staabm staabm marked this pull request as ready for review May 16, 2022 19:35
@ondrejmirtes ondrejmirtes merged commit f52dc41 into phpstan:1.7.x May 17, 2022
@ondrejmirtes
Copy link
Member

Thank you!

@staabm staabm deleted the subclass-strings branch May 17, 2022 07:49
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.

False-positive with is_subclass_of
3 participants