-
-
Notifications
You must be signed in to change notification settings - Fork 864
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
Improvements to switch/case exhaustiveness checking #3488
Comments
The third one was easy: phpstan/phpstan-strict-rules@82c19b1 |
@Firehed PHPStan now reports different result with your code snippet: @@ @@
15: Method C::allCovered() should return int but return statement is missing.
27: Method C::invalidCase() should return int but return statement is missing.
-27: Switch condition type ('a'|'b'|'c') does not match case condition 'd' (string).
+31: Switch condition type ('a'|'b'|'c') does not match case condition 'd' (string). Full report
|
Adding my vote to this one. doesn't make sense to require a default in these cases. |
@Firehed After the latest commit in dev-master, PHPStan now reports different result with your code snippet: @@ @@
-15: Method C::allCovered() should return int but return statement is missing.
-27: Method C::invalidCase() should return int but return statement is missing.
-27: Switch condition type ('a'|'b'|'c') does not match case condition 'd' (string).
+-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
|
Somewhere between pre-1.0 and now |
I am current experiencing false positive related to second point you are describing. Minimal playground: https://phpstan.org/r/b967b249-3d2b-4ed5-9cbb-eadd88777a2c |
@peldax Your example got fixed: phpstan/phpstan-src#2687 |
@peldax After the latest push in 1.11.x, PHPStan now reports different result with your code snippet: @@ @@
-PHP 8.1 – 8.2 (1 error)
+PHP 8.1 – 8.2
==========
-11: Function testFunction() should return int but return statement is missing.
+No errors
PHP 7.2 – 8.0 (1 error)
==========
3: Syntax error, unexpected T_STRING on line 3 Full reportPHP 8.1 – 8.2No errors PHP 7.2 – 8.0 (1 error)
|
Feature request
When using the const-as-enum pattern (supported in 0.12.20 via #2904), it would be really helpful to improve several warnings. Turning on strict rules does handle explicitly invalid cases (IMO that should be in the default rules, but that's a different conversation), but
default
s get a bit weird:case
line rather thanswitch
https://phpstan.org/r/e3457146-1c41-4e70-9740-fe5d67f7f987
The text was updated successfully, but these errors were encountered: