Add Type::getUnionedTypes(), deprecate TypeUtils::flattenTypes()#1922
Add Type::getUnionedTypes(), deprecate TypeUtils::flattenTypes()#1922herndlm wants to merge 1 commit intophpstan:1.9.xfrom
Type::getUnionedTypes(), deprecate TypeUtils::flattenTypes()#1922Conversation
3d47633 to
1d5bd62
Compare
|
the 11 failing "normal" tests are expected, it's the regression test that I mentioned in the description the 4 phpstan failures seem to be related to recent changes on 1.9.x and the interesting part I wanted to check are the 2 integration failures. I think both of them are fine. |
1d5bd62 to
b83b678
Compare
|
I don't love this very much, I spoke against dressing flattenTypes as a new method here #1687 (comment). My problem with that is that it doesn't describe any specific use-case, and can be wrongly used or implemented. I'm for methods that feel more like a specific use-case. BTW we don't have to drain all array use cases before moving on, I'd rather address wrong usages that are most common, like:
To me it feels like these usages should be replaced with |
|
ok, got you. I started having this obsession a while ago, where the final goal is to get rid of the mentioned |
Just an idea I had already a while ago and wanted to discuss. The essence of flattenTypes() is to get the inner types of a union or pass-through the current type in case it's not a union, which is how I came to that name.
I dislike a bit that it's another very specific thing again. But I didn't come up with something smarter / more generic.
And there is still a problem with the regression test for phpstan/phpstan#6379 in
NonexistentOffsetInArrayDimFetchCheckwhich I couldn't figure out yet. But I also don't really understand the narrowed types, see https://phpstan.org/r/788351dc-d1f1-4a17-a6a5-f0120a32222e. The error that is reported is16: Offset 'c' does not exist on array{cr?: string, c?: string}&non-empty-array..