Do not create a throw point for void returned by dynamic throw type extensions - #6515
Merged
Merged
Conversation
…xtensions A dynamic function, method or static method throw type extension returning VoidType produced an explicit throw point of type void. It kept variables assigned in a try block only maybe-defined in finally, kept catch (Throwable) alive, made rules iterating explicit throw points see a throw, and was reported as "throws exception void" in functions with @throws void. Treat it as no throw point, the same way a @throws void declaration is treated. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Dhb4ssXuKVWcVBcNFpsdn7
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Returning
VoidTypefrom aDynamicFunctionThrowTypeExtension,DynamicMethodThrowTypeExtensionorDynamicStaticMethodThrowTypeExtension(also fornew) created an explicit throw point of typevoid, instead of saying that the call does not throw. As a result:tryblock was only maybe-defined infinally,catch (\Throwable $e)around the call was not reported as dead,@throws voidcalling it was reported withthrows exception void but the PHPDoc contains @throws void,$throwPoint->isExplicit()) saw a throw.Ds\Map::get()/remove()with a default value (DsMapDynamicMethodThrowTypeExtension) are affected today.A
@throws voiddeclaration without an extension already produces no throw point (FuncCallHandler::getFunctionThrowPoint()skips it when$throwType->isVoid()->yes()). This PR does the same in the extension branches ofFuncCallHandler,MethodThrowPointHelperandNewHandler.This is groundwork for the upcoming throw type extensions for functions that PhpStorm stubs now declare as throwing
ValueErrorand similar (min()/max(),sprintf(), ...). They will returnVoidTypewhen the call cannot throw.Tests:
DynamicMethodThrowTypeExtensionTestwith new test extensions returningVoidTypefor a function, a method, a static method and a constructor (variable certainty infinally)CatchWithUnthrownExceptionRuleTest::testDsMapVoidThrowType()for the realDs\MapextensionBoth fail without the change.
🤖 Generated with Claude Code
https://claude.ai/code/session_01Dhb4ssXuKVWcVBcNFpsdn7