Repository navigation
Keep the native values the PHPDoc type rules out in disjunction branch unions - #7220
Merged
Merged
Conversation
…h unions DisjunctionBranchUnionAugment and DisjunctionHolderProjectionAugment pin the union of the subject's types in the two branches of `||` (or of a negated `&&`) as a sure type. Those branch types are PHPDoc types, and applySpecifiedTypes() intersects a sure type into the native type too, so with treatPhpDocTypesAsCertain: false a PHPDoc-only array shape became the native type of a parameter without a native type, and rules reported errors based on it. The exact union of shapes since 0e9fdb5 exposed it: before, the two branch shapes merged back into the original shape and the augment did not fire. Where the PHPDoc type of the subject describes more than its native type, the subject's entry is now the alternative of the union and of whatever the PHPDoc type does not describe. The PHPDoc type still narrows to the union; the native type keeps every value the PHPDoc type rules out and only loses the values the condition itself excludes. A subject whose native type equals its PHPDoc type still narrows both to the union. turbo-ext: the same in both augments, through one shared helper. Amp-Thread-ID: https://ampcode.com/threads/T-01a21c4a-d975-75f9-9537-a0c2fc5fdea6
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.
Closes phpstan/phpstan#15858
DisjunctionBranchUnionAugmentandDisjunctionHolderProjectionAugmentpin the union of the subject's PHPDoc types in the two branches of||as a sure type, andapplySpecifiedTypes()intersects a sure type into the native type too. WithtreatPhpDocTypesAsCertain: false, a PHPDoc-only array shape became the native type of a parameter without a native type (Dolibarr:nullCoalesce.offset). The leak predates 0e9fdb5 (e.g. the nativearrayofbug-14566became the PHPDoc shape); the exact shape union only made the augment fire in this case.Where the PHPDoc type describes more than the native type, the subject's entry is now the alternative of the union and of whatever the PHPDoc type does not describe (built with the existing
SpecifiedTypes::intersectWith()):mixed~array{http_code: 200, content: non-falsy-string}for the issue's snippet.ImpossibleInstanceOfRuleTestline 234 now carries the PHPDoc tip:$intersectionhas no native type, so the always-false verdict comes from PHPDoc only.turbo-ext: the same in both augments through one shared helper; smoke, signature parity and the full walk-trace corpus are identical, and analysis output is byte-identical with the extension on and off.