Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[ObjectMapper] Fix TargetClass generic type in ConditionCallableInterface#64358

Merged
nicolas-grekas merged 1 commit into
symfony:7.4from
mudassaralichouhan:fix/object-mapper-target-class-type
May 28, 2026
Merged

[ObjectMapper] Fix TargetClass generic type in ConditionCallableInterface#64358
nicolas-grekas merged 1 commit into
symfony:7.4from
mudassaralichouhan:fix/object-mapper-target-class-type

Conversation

@mudassaralichouhan
Copy link
Copy Markdown
Contributor

@mudassaralichouhan mudassaralichouhan commented May 24, 2026

Q A
Branch? 7.4
Bug fix? yes
New feature? no
Deprecations? no
Issues Fix #64340
License MIT

TargetClass declared @implements ConditionCallableInterface<object, T>, which narrows the target generic to the className type. However, __invoke accepts any ?object at runtime (it only checks instanceof internally), so this generic binding was over-specified.

The mismatch caused a PHPStan error when using TargetClass as the if condition of #[Map]:

#[Map(if: new TargetClass(self::class))]

PHPStan inferred the callable as callable(mixed, object, ?Foo): bool, which is not contravariantly compatible with the callable(mixed, object, ?object): bool type expected by Map::$if.

Fixing the @implements binding to <object, object> aligns the generic annotation with the actual runtime behavior, with no BC break — @template T of object is preserved so $className keeps its class-string<T> constraint.

@carsonbot carsonbot added this to the 8.1 milestone May 24, 2026
@mudassaralichouhan mudassaralichouhan force-pushed the fix/object-mapper-target-class-type branch 2 times, most recently from 3337d11 to bfc8ee3 Compare May 24, 2026 13:49
@fabpot fabpot modified the milestones: 8.1, 8.2 May 25, 2026
@nicolas-grekas nicolas-grekas modified the milestones: 8.2, 7.4 May 25, 2026
@symfony symfony deleted a comment from carsonbot May 25, 2026
@nicolas-grekas
Copy link
Copy Markdown
Member

For 7.4, isn't it?

@mudassaralichouhan
Copy link
Copy Markdown
Contributor Author

@nicolas-grekas Yes, 7.4 it is

@nicolas-grekas
Copy link
Copy Markdown
Member

Thank you @mudassaralichouhan.

@nicolas-grekas nicolas-grekas merged commit 9359397 into symfony:7.4 May 28, 2026
5 of 14 checks passed
@fabpot fabpot mentioned this pull request May 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[ObjectMapper] Type issue with TargetClass in Map attribute if parameter

4 participants