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

How to annotate methods that always throw? #3602

Closed
Daimona opened this issue Dec 23, 2019 · 1 comment
Closed

How to annotate methods that always throw? #3602

Daimona opened this issue Dec 23, 2019 · 1 comment
Labels
duplicate This is a duplicate of a linked issue enhancement This improves the quality of Phan's analysis of a codebase

Comments

@Daimona
Copy link
Member

Daimona commented Dec 23, 2019

In MediaWiki, all API modules use a method, dieWithError, which simply throws an exception.

AFAICS, phan cannot automatically determine that calling dieWithError will always throw, hence leading to false positives. See the bug report downstream for a couple of examples.

I wonder whether there could be an annotation to make phan infer that a method will always throw (maybe something along the line of @phan-assert, but unconditional).

@TysonAndre TysonAndre added duplicate This is a duplicate of a linked issue enhancement This improves the quality of Phan's analysis of a codebase labels Dec 23, 2019
@TysonAndre
Copy link
Member

There's currently no way to do this. See #2118 for discussion on how this would be implemented in the future.

TysonAndre added a commit to TysonAndre/phan that referenced this issue May 15, 2021
Closes phan#2118
Closes phan#4405
Related to phan#3602

Allow using closures, global functions, and instance/static methods as
custom exit/error functions if they have a return type of never.
Note: This may result in false positives for control flow analysis of
unreachable types if object instances with different return types are
passed in, in different invocations of methods

Start using `no-return` in Phan itself for phpdoc
(in other tools, handling on `never` depends on the php version used)

Fix parsing of new hyphenated `@return no-return|never-returns?` type.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
duplicate This is a duplicate of a linked issue enhancement This improves the quality of Phan's analysis of a codebase
Projects
None yet
Development

No branches or pull requests

2 participants