[6.x] Resolve method templates for polymorphic array callables#11815
Open
[6.x] Resolve method templates for polymorphic array callables#11815
Conversation
When a `[Class::class, 'method']` array is passed where a specialised callable signature is expected, infer the method's `@template` params from the container signature instead of leaving them as raw template standins. The previous behaviour produced spurious `InvalidArgument` errors because the container types could not match the template atoms. Fixes vimeo#6549
1e5e74d to
a99132c
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.
Fixes #6549.
Passing
[Class::class, 'method']to a specialised callable parameter used to tripInvalidArgumentwhen the method was templated, because the method's@templateatoms were carried into the callable unchanged and nothing would later matchintagainstB.Before / after
Before:
InvalidArgument—callable(int): intvscallable(B as mixed): B as mixed.After: accepted,
Bis inferred asintfrom the container.What changed
In
CallableTypeComparator::getCallableFromAtomic, theTKeyedArraybranch now wraps the built callable in aUnionand runsfillTemplateResult+TemplateInferredTypeReplacer::replaceagainst the container callable — the same idiom the invokable-class branch below already uses. The template walker handles param/return variance and falls unmatched templates back to their declared bounds, so nothing leaks.Guarded on
template_types !== null && container_type_part !== null, so callers that don't supply a container (e.g.ClosureFromCallableReturnTypeProvider,ScalarTypeComparator) are untouched.Note
Medium Risk
Changes callable type construction for array-callables to resolve method-level templates using the expected callable signature, which can affect type-checking outcomes across projects using templated methods as callables.
Overview
Fixes handling of templated methods used as array callables (e.g.
[Class::class, "method"]) by resolving method-level templates against the expected callable type when building aTCallableinCallableTypeComparator::getCallableFromAtomic.Adds coverage for polymorphic static/instance/multi-template array callables (including
array_map) and a negative test ensuring mismatched expected return types still raiseInvalidArgument.Reviewed by Cursor Bugbot for commit 90abfd0. Bugbot is set up for automated code reviews on this repo. Configure here.