Repository navigation
Native types of class constants and tentative return types, walk dead catches and closure attributes - #6859
Open
ondrejmirtes wants to merge 1 commit into
Open
Native types of class constants and tentative return types, walk dead catches and closure attributes#6859ondrejmirtes wants to merge 1 commit into
ondrejmirtes wants to merge 1 commit into
Conversation
… catches and closure attributes - Native type of a class constant fetch no longer comes from its @var PHPDoc: a constant that can be overridden resolves to its native type, or mixed - Tentative return types of built-in methods are used as their native return types on PHP 8.1+ - Catch blocks that no throw point reaches are walked, so rules see their statements - Attribute groups of closures and arrow functions are walked like those of functions and methods Amp-Thread-ID: https://ampcode.com/threads/T-01a179f2-995f-7745-8d8c-4c174ba5c0ce
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.
Four fixes found while auditing where Rector works around PHPStan behaviour.
Native type of class constant fetches ignored
@var.getNativeType()ofstatic::FOOon a non-final class returned the@varPHPDoc type, so withtreatPhpDocTypesAsCertain: falsecomparisons likestatic::FOO === ''were reported as always false. With native types promoted, the PHPDoc type is no longer used: an overridable constant resolves to its native type, or tomixedwithout one. Final constants and constants of final classes still resolve to their value.Tentative return types of built-in methods are native return types.
getNativeType($arrayObject->count())wasmixed. On PHP 8.1+ the tentative return type is now the native return type when the signature has none. Before PHP 8.1,OverridingMethodRuleno longer reports return types that are only tentative (previously this relied on the native type beingmixed).Dead catch blocks are walked. When no throw point matched a catch, its statements were never analysed, so
catch (\InvalidArgumentException $e) { $e->nonExistent(); }after a try that cannot throw only reported "Dead catch". The body is now walked with the declared catch type; the result does not flow into the rest of the function.bug-14397andtestBug4043expectations changed accordingly (the catch body is now analysed, so$foois maybe-defined there, and atreatPhpDocTypesAsCertaintip is no longer shown).Attributes of closures and arrow functions are walked through
AttributesHandler, like those of functions and methods, so rules such asClassConstantRulesee their arguments.All four have the matching turbo-ext changes. Tests pass with and without the extension;
make phpstanandmake csare clean;side-by-side.php,signature-parity.phpandsmoke.phppass.