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

FP: is_subclass_of() with non-empty-string #5369

Closed
voku opened this issue Jul 23, 2021 · 6 comments
Closed

FP: is_subclass_of() with non-empty-string #5369

voku opened this issue Jul 23, 2021 · 6 comments
Labels
Milestone

Comments

@voku
Copy link
Contributor

voku commented Jul 23, 2021

Bug report

Code snippet that reproduces the problem

https://phpstan.org/r/e24cf39e-68f1-4c66-b1be-0c39189b721a

Expected output

no error because it's maybe true or false

Did PHPStan help you today? Did it make you happy in any way?

It improves the code quality step by step, and that is what good progress looks like. 🥇

@phpstan-bot
Copy link
Contributor

@voku After the latest commit in dev-master, PHPStan now reports different result with your code snippet:

@@ @@
- 9: Call to function is_subclass_of() with non-empty-string and 'BrandBase' will always evaluate to false.
+-1: Internal error: PHPStan\Rules\Methods\WrongCaseOfInheritedMethodRule::findMethod(): Argument #2 ($classReflection) must be of type PHPStan\Reflection\ClassReflection, null given, called in /var/task/vendor/phpstan/phpstan-strict-rules/src/Rules/Methods/WrongCaseOfInheritedMethodRule.php on line 40
+Run PHPStan with --debug option and post the stack trace to:
+https://github.com/phpstan/phpstan/issues/new?template=Bug_report.md
Full report
Line Error
-1 Internal error: PHPStan\Rules\Methods\WrongCaseOfInheritedMethodRule::findMethod(): Argument #2 ($classReflection) must be of type PHPStan\Reflection\ClassReflection, null given, called in /var/task/vendor/phpstan/phpstan-strict-rules/src/Rules/Methods/WrongCaseOfInheritedMethodRule.php on line 40Run PHPStan with --debug option and post the stack trace to:https://github.com/phpstan/phpstan/issues/new?template=Bug_report.md

@phpstan-bot
Copy link
Contributor

@voku After the latest commit in dev-master, PHPStan now reports different result with your code snippet:

@@ @@
-9: Call to function is_subclass_of() with non-empty-string and 'BrandBase' will always evaluate to false.
+6: Method BrandLib::getBrandObjectBySkinname() should return BrandBase|null but return statement is missing.
Full report
Line Error
6 `Method BrandLib::getBrandObjectBySkinname() should return BrandBase

@Garfunkiel
Copy link
Contributor

I did some testing with commits from around the time this stopped working, and phpstan/phpstan-src@1283db7 was the commit where the change occurred (the commit right before that one reported no problems for the example snippet). Looking at it and reverting some of the changes from that commit individually, I was able to determine that the cause is this addition around line 1049 of src/Analyser/MutatingScope.php:

if ($leftStringType->isNonEmptyString()->or($rightStringType->isNonEmptyString())->yes()) {
	return new IntersectionType([
		new StringType(),
		new AccessoryNonEmptyStringType(),
	]);
}

I'm not sure what the right change would be, though, since I'm not particularly familiar with PHPStan's code.

@phpstan-bot
Copy link
Contributor

@voku After the latest commit in dev-master, PHPStan now reports different result with your code snippet:

@@ @@
-9: Call to function is_subclass_of() with non-empty-string and 'BrandBase' will always evaluate to false.
+No errors

@ondrejmirtes
Copy link
Member

Fixed: phpstan/phpstan-src@73f14db

@github-actions
Copy link

github-actions bot commented Apr 1, 2022

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 1, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

4 participants