Repository navigation
Conversation
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
zonuexe
force-pushed
the
template-never-bound
branch
from
November 14, 2026 16:25
483222f to
70abdae
Compare
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.
When a narrowing removes every value a template's bound allows,
TemplateTypeTrait::subtract()andtryRemove()pass aneverbound toTemplateTypeFactory::create(). The factory has no case for it and falls back to amixedbound, so a branch that cannot be reached holds a mixed-boundT, and merging that branch back widens the variable for the rest of the function. This PR returnsneverfrom both methods instead.Impact
T of int $t, in theelseofif ($t >= 0)insideif ($t > 0)T of mixed~(bool|float<0.0, max>|null)*NEVER*ifT of mixed~(…)T of int<1, max>T of int $t, in theelseofif ($t < 0) … elseif ($t >= 0)T of mixed~(…)*NEVER*T of int $t, afterif ($t < 0) {}, insideif ($t >= 2 && $t <= 2)T of mixed~(…)T of 2T of bool $t, in theelseofif ($t === true) … elseif ($t === false)T*NEVER*$tafterwards was reported asshould return T of int but returns T of mixed, orshould return T of bool but returns T.T of floatnow that Keep a narrowed float bound when creating a template type #7070 keeps a narrowed float bound.Fix
subtract()andtryRemove()now return theneverthatTypeCombinator::remove()gives for the bound. If no value of the bound is left, no value ofTis left either. The nativeTemplateTypeTraitin turbo-ext gets the same change.Testing
tests/PHPStan/Analyser/nsrt/template-never-bound.phpcovers the cases in the table and aT of stringchecked byis_string().ReturnTypeRuleTest::testTemplateNeverBound()runs the same functions:intwhereTis expected is still reported.mixedfrom aTwith amixedbound, so it sees the change. With the PHP twin at the base,smoke.phpreports the native*NEVER*as a mismatch.