You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am returning a class-string from a method which could also return null in the default generic case (using a conditional return type declaration). The returned class-string type is not checked in the context of the child class but in the generic context of the parent/definer and thus not part of the generic template variable.
This code shouldn't have any issues as DeleteActionType implements DataClassAwareFormTypeInterface<DeleteActionParameters> and DeleteActionParameters is of Struct
Did PHPStan help you today? Did it make you happy in any way?
Most of the time, PHPStan is more intelligent than I am - discovering issues with covariance and contravariance I otherwise would've missed :)
The text was updated successfully, but these errors were encountered:
jankal
changed the title
Optional template parameter not resolved when used
Conditional return inclusing template type resolved in wrong place
Dec 29, 2024
jankal
changed the title
Conditional return inclusing template type resolved in wrong place
Conditional return type including template type resolved in wrong place
Dec 29, 2024
@staabm yeah, that works for setting the default in the generic and omitting the generic parameter when the default should be used.
The actual bug is about PHPStan apparently checking the return type in the wrong context (error says, the return type of that function is not part of the template parameter... which it is as it is of Struct).
Bug report
I am returning a class-string from a method which could also return null in the default generic case (using a conditional return type declaration). The returned class-string type is not checked in the context of the child class but in the generic context of the parent/definer and thus not part of the generic template variable.
Code snippet that reproduces the problem
https://phpstan.org/r/ea335711-73a7-4d4e-9647-9212eef29f75
Expected output
This code shouldn't have any issues as
DeleteActionType implements DataClassAwareFormTypeInterface<DeleteActionParameters>
andDeleteActionParameters
isof Struct
Did PHPStan help you today? Did it make you happy in any way?
Most of the time, PHPStan is more intelligent than I am - discovering issues with covariance and contravariance I otherwise would've missed :)
The text was updated successfully, but these errors were encountered: