Repository navigation
Create the implicit throw point of a constructor on the new expression - #6687
Merged
ondrejmirtes merged 2 commits intoOct 6, 2026
Merged
ondrejmirtes merged 2 commits into
ondrejmirtes merged 2 commits into
Conversation
getConstructorThrowPoint() builds a synthetic StaticCall for the dynamic throw type extensions and ArgumentsNormalizer. The explicit throw points are created on the New_ expression, but the implicit one was created on the synthetic StaticCall, which has no file positions, so VariableFlowBuilder::throws() dropped it. TryCatchHandler still saw it, so the catch was reachable for CatchWithUnthrownExceptionRule but dead for the variable liveness analysis, and UnusedMethodParametersRule reported a parameter read only inside such a catch as unused.
Member
|
Thank you! |
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.
NewHandler::getConstructorThrowPoint()builds a syntheticStaticCallso that dynamic throw type extensions andArgumentsNormalizercan work with the constructor call. The explicit throw points (from@throwsor from an extension) are created on theNew_expression, but the implicit one (constructor without@throws,exceptions.implicitThrows: true) was created on the syntheticStaticCall.That node has no file positions, so
VariableFlowBuilder::throws()drops the throw point: it keeps only throw points whose node is the expression itself or shares its start/end positions.TryCatchHandlerworks with the throw points directly and still sees it, so the two analyses disagree: thecatchis reachable forCatchWithUnthrownExceptionRule(no "Dead catch" is reported), but it is dead for the variable liveness analysis behindUnusedMethodParametersRule, which then reports a parameter read only inside such acatchas unused.This PR creates the implicit throw point on
$new, like the explicit ones. The turbo mirror inturbo-ext/src/NewHandler.cppgets the same change, followed by themake bump-turbocommit. The regression test data is the reproducer from the issue's playground link.Verified locally:
make tests(22448 tests), the new regression test fails before the change and passes after it, both with and without the turbo extension loaded;tests/PHPStan/Rules/Exceptionsalso passes with the extension loaded.Closes phpstan/phpstan#15396