Open dbalabka opened 4 years ago
May be related to #6940.
Looks like @psalm-type
declarations are not visible in @throws
either.
Update: I see that I had actually been here before. Why was my comment marked as off-topic? Aren't the errors I am getting (crashing my builds) related to type validation in @throws
?
Please, I would very much like to have this. Is there any plan or even intention? Is this a feature that is already decided to be OK?
I found these snippets:
Recently, I have faced the problem that it is impossible to control what kind of exceptions may be thrown by interface implementations. It would be great to restrict to throw an exception that not declared in the interface doc block (or in any overrode method).
For example, Java supports the possibility to declare what exceptions can be thrown by the method using throws in the method declaration. Java also validates that the overridden method should throw only those exceptions that declared in the parent method or exceptions of compatible types.
In the following example, Psalm should point that
WrongImplementation::get()
throws an exception that isn't supported by the interfaceSomeInterface::get()
:https://psalm.dev/r/ecf23dae78
Example of implementation: https://github.com/pepakriz/phpstan-exception-rules/blob/master/tests/src/Rules/data/throws-inheritance.php#L90