New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix/issue 7000 2 #1307
Fix/issue 7000 2 #1307
Conversation
src/Analyser/MutatingScope.php
Outdated
if (!$dimType instanceof UnionType) { | ||
foreach ($constantArrays as $constantArray) { | ||
$setArrays[] = $constantArray->setOffsetValueType( | ||
TypeCombinator::intersect(ArrayType::castToArrayKeyType($dimType), $constantArray->getKeyType()), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Move the cast before the loop?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes! thanks
Checked the failing integration tests, but I think they're all correct to report. ;) |
I love this! Thank you very much :) |
fixes phpstan/phpstan#6508
fixes phpstan/phpstan#7000
fixes phpstan/phpstan#7190
see #1299
This is (a little hacky) solution to solve
isset
expression specifying now.There are two problems in
specifyExpressionType
forArrayDimFetch
(that cannot be solved easily I think) now.ArrayDimFetch
with the same type of the current value can change the type in some casesex. https://phpstan.org/r/941b7692-8141-4fee-a410-303706ad0abf
this case was skipped before c0bf915, but the current implementation of type specifying changes the type to 'array{id: int|string, name: int|string}'
phpstan-src/src/Analyser/NodeScopeResolver.php
Lines 1593 to 1607 in 58b6023
A - (specify B) > -(specify A)> !== A
For example, we cannot know whether the offset was marked as required or not before the specification. (maybe phpstan/phpstan#7224 is related to this problem)
array{ 'optional'?: string|null } - (specify non null) > array{ 'optional': string } - (specify null) >
array{ 'optional': string|null } - (specify non null) > array{ 'optional': string } - (specify null) >
I had to skip $dimType with
UnionType
bd2eb4e because of these reasons (for now).