Conversation
|
The failing test is obviously wrong. But we should preserve that for example |
|
|
||
| if ( | ||
| ($leftType->isArray()->yes() || $rightType->isArray()->yes()) | ||
| && ($leftType instanceof MixedType || $rightType instanceof MixedType) |
There was a problem hiding this comment.
My suspicion is that this has a number of problems. Doing instanceof *Type is rarely right so it's not hard to poke holes into the logic - this handles the mixed scenario but what about something else that "may be" an array or int? What if we do int|array + int|array? What piece of code will handle that?
There was a problem hiding this comment.
Also this condition will catch TemplateMixedType, maybe there's a situation which will cause generics to be lost.
There was a problem hiding this comment.
Also - MixedType is subtractable, meaning there can be a mixed~array|int type which means "this is mixed but it's definitely not int nor array". My point is - doing isSuperTypeOf() is much safer and usually more correct than instanceof :) More about it here: https://phpstan.org/developing-extensions/type-system#querying-a-specific-type
Fixes phpstan/phpstan#7492