Repository navigation
Narrow native types by conditional expression holders - #7177
Merged
Merged
Conversation
A holder narrowed only the PHPDoc type of its target, so `$ok = $x !== null; if ($ok)` left the native type of $x nullable: a later `$x === null` was reported with the PHPDoc tip in code without PHPDoc, and not at all with treatPhpDocTypesAsCertain: false. A matched holder now narrows the native type too when the target and every guard have native types equal to their PHPDoc types: the PHPDoc knowledge the holder's type carries is then implied by the native types. Amp-Thread-ID: https://ampcode.com/threads/T-01a17eac-1199-74a6-b3f7-dfbd8a084465
This was referenced Nov 27, 2026
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.
Conditional expression holders narrowed only the PHPDoc type of their target, never the native type:
The function has no PHPDoc, so the tip is wrong, and with
treatPhpDocTypesAsCertain: falsethe always-false comparison is not reported at all. Branch-merge holders (if ($b) { $y = $x ?? 1; } else { $y = null; } if ($b) …) behave the same.A matched holder now narrows the native type too when the target and every guard currently have native types equal to their PHPDoc types. The holder's type may carry PHPDoc knowledge from where it was created, but then the native type implies everything the PHPDoc type does, so intersecting with it adds no PHPDoc assumption. A PHPDoc-typed target or guard keeps its native type unnarrowed (covered in
nsrt/conditional-expression-native-types.php).This is the reduced product of the two analyses (Cousot & Cousot 1979): every transfer function updates both components.
Two existing expectations lose the PHPDoc tip they had wrongly:
ImpossibleInstanceOfRuleTest::testBug3632andBooleanNotConstantConditionRuleTest::testBug11903, neither of which has any PHPDoc.turbo-ext mirrors the change.