-
Notifications
You must be signed in to change notification settings - Fork 359
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
Custom exit/error functions #2118
Comments
My current thoughts would be to support these checks with global functions and static method invocations (i.e. anything that can be inferred without knowing variable types and added to a more precise BlockExitStatusChecker) |
That's reasonable. It should be rare to have dynamic functions that always exit. |
The other approach would be to manually set all of the flags at runtime (for instance flags), and recursively invalidate and recompute the flags for parent nodes until they stop changing or the end of the current function scope is reached |
This type should be used mainly as a return type to designate a function/method as a never returning back. It shows that the function/method will always throw an exception or will call `exit()` or will call `trigger_error()` or will stop program execution in any other available way. This return type is available in many languages/tools: 1. Kotlin — `Nothing` return type. See https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-nothing.html 2. Hack lang — `noreturn` return type. See https://docs.hhvm.com/hack/built-in-types/noreturn (examples: https://github.com/facebookarchive/hack-langspec/blob/master/tests/Functions/noreturn.php) 3. Vimeo Psalm — `@return no-return` PhpDoc type. See vimeo/psalm#1155 (comment) + they have config option, but it's only for functions/static methods and is going to be deprecated/removed in the future. 4. Phpstan has @return never PhpDoc type. See phpstan/phpstan#1472 + they have config option and it's possible to specify dynamic method calls there too. 5. Phan doesn't have this — see phan/phan#2118, but they plan to add it. 6. PhpStorm doesn't have this feature, but they plan to add it and the PhpDoc tag is not decided yet. See https://youtrack.jetbrains.com/issue/WI-10673
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.
Thanks! |
Sometimes, it's helpful to use a custom function that always exits. Psalm now detects these automatically and allows them to be configured, but I couldn't find the same for Phan.
Example:
Example output:
The text was updated successfully, but these errors were encountered: