Repository navigation
[6.x] Resolve method templates for polymorphic array callables - #11815
Merged
Merged
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
alies-dev
force-pushed
the
fix/6549-polymorphic-array-callable
branch
from
April 18, 2026 16:14
1e5e74d to
a99132c
Compare
Collaborator
|
fix failing CI pls |
Contributor
Author
|
Fixed: the self-analysis failure came from |
Contributor
Author
|
The version merged here predates the self-analysis fix and the soundness guards for defaults, variadics and template bounds; those are in #12012, which also removes the |
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
[Id::class, 'id']to acallable(int): intparameter used to fail withInvalidArgumentwhenId::idhas its own@template B(@param B $b,@return B), because the method's templates were carried into the callable unresolved and nothing later matchedintagainstB.When the expected callable is known,
CallableTypeComparator::getCallableFromAtomicnow infers the method's templates from it: each parameter is bound to the argument type the expected callable passes at that position (a variadic parameter to every remaining argument), and the return type to the expected return type unless that isvoid. Arguments the expected callable may omit bind to the parameter's default value, with unresolved constant defaults or otherwise uninferred defaults treated asmixed.Inference only ever makes the callable more specific when that is safe. If a template would land outside its declared bound (for example through
class-string), or if any argument, including a default, is not accepted by the resolved parameter type, the templates stay unresolved and the comparison reports the mismatch as before. Tests cover the accepted cases (static, instance, multiple templates,array_map, nested callables, variadics, defaults, void returns) and the rejected ones. The invokable-object branch now uses the samereplaceTemplateTypesWithArgTypeshelper, which keeps the result typed asTCallableand removes two baseline entries.