-
-
Notifications
You must be signed in to change notification settings - Fork 929
Description
Bug report
When there is a union type parameter in a function that is only set via the docblock (not as part of the signature), it makes sense to throw an exception if an invalid type is used for said parameter. This means you'd have if-statements working on the various supported types with a final exception thrown if none of the if-statements passed.
PHPStan, however, views the final exception as unreachable. It reasons that if there's an if-statement for each documented type then the exception itself is unreachable. This would be true if the signature had types, but if not true if it's just documented as such. In runtime any type could be passed to the parameter and PHP wouldn't see a problem.
Code snippet that reproduces the problem
https://phpstan.org/r/82dbf91b-d779-41ff-8944-5f15378aa991
Expected output
If the parameter types are not a part of the signature then PHPStan should not view the subsequent code as unreachable.
Did PHPStan help you today? Did it make you happy in any way?
PHPStan is awesome and 99.9% of the time brings so much stability to projects! Y'all are amazing for maintaining such a valuable project!