fix makeOffsetRequired with UnionType offset#1187
Conversation
|
Hi, this fix isn't right. When you have a union type, the value is one of the inner types. So checking In fact this is really hard to fix in typesystem alone. The closest thing we can get after the isset is something like: But that still doesn't help us to get rid of the error when asking about What we can do to fix this is to let TypeSpecifier specify And the right rule needs to pick up this information and not report the error. You also need to write a regression test for the rule instead of NodeScopeResolverTest. |
Oh, you're right. Thank you for the pointers! I'll continue looking into it. |
|
Feel free to finish the other PR related to Coalesce/Isset_ first, that might have a bigger impact 😊 |
I’ll finish it today! |
|
I believe this is now an improvement for The problem (I think) is that type in isset scope should be phpstan-src/src/Analyser/TypeSpecifier.php Lines 785 to 790 in 036056b should be an conditional type if $var->dim is a UnionType
|
|
I'll read this #1187 (comment) again and look for a fix if possible |
|
improving type to |
|
I'd close this for now. I think it's not easy enough to solve cleanly, and there are other related issues to solve before this. |
fixes phpstan/phpstan#7000
$offsetTypewithUnionTypeshould be handled separately like inhasOffsetValueTypehttps://github.com/phpstan/phpstan-src/blob/5066420056515058bb081b40d221571db66568d8/src/Type/Constant/ConstantArrayType.php#L412-L419