Repository navigation
Let callbacks see values added to a type variable after its construction - #14551
Merged
orklah merged 1 commit intoNov 23, 2026
Merged
Conversation
… variable
Untyped closure params, callable params and the template gate resolved a
type variable through its construction-site bounds only, so after
`$c = new Coll([1]); $c->add("x");` folding `$c->all()` with
array_reduce reported IncompatibleTypeParameters and lost 'x'.
Fixes #13841
Contributor
✅ Performance: unchanged · Types: unchanged
How to read this table
head 4758ff3 · base e63cd9f (merge-base) · workflow run |
Collaborator
|
Thanks! |
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.
A callback over the elements of a widened class type variable (
new Coll([1]), then$c->add("x")) only sees the construction-site bound, so folding or mapping the list reportsIncompatibleTypeParametersand drops the added values.Before
After
Untyped closure params and the template gate now resolve the variable through every value that reached it, as read sites already do since 7cc951c. A typed callable param is left live only when the callback takes the construction-site values but none of the later ones, so each too-narrow callback is reported once:
new Coll([new A()]); $c->add(new B()); $c->each(function (A $a): void {});stays oneType B should be a subtype of Aat the method name, as on master;new Coll([1]); $c->add("x"); $c->each(function (int $i): void {});is nowType 'x' should be a subtype of intat the callback argument (col 14) instead of... of 1at the method name (col 9);InvalidArgument, and one that takes every value (object,int|string) is no longer reported.HHVM agrees (two new
type_variablesfixtures), and the type-variable rule in thehack-conformanceskill anddocs/annotating_code/type_variables.mdare updated to match.Ran locally: lint, phpcs, self-analysis,
HackConformanceTestand the PHPUnit suite, without 4 tests that fail on unchanged master in my container too (testGeneratorRejectsMissingRequiredExtensionBeforeWriting,taintPropertyPassingObjectWithDifferentValuex2, thestr_contains/__DIR__case).Fixes #13841