Fix/issue 7000 2#1307
Merged
Merged
Conversation
staabm
reviewed
May 12, 2022
| if (!$dimType instanceof UnionType) { | ||
| foreach ($constantArrays as $constantArray) { | ||
| $setArrays[] = $constantArray->setOffsetValueType( | ||
| TypeCombinator::intersect(ArrayType::castToArrayKeyType($dimType), $constantArray->getKeyType()), |
Contributor
There was a problem hiding this comment.
Move the cast before the loop?
Contributor
Author
|
Checked the failing integration tests, but I think they're all correct to report. ;) |
Member
|
I love this! Thank you very much :) |
This was referenced May 12, 2022
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
fixes phpstan/phpstan#6508
fixes phpstan/phpstan#7000
fixes phpstan/phpstan#7190
see #1299
This is (a little hacky) solution to solve
issetexpression specifying now.There are two problems in
specifyExpressionTypeforArrayDimFetch(that cannot be solved easily I think) now.ArrayDimFetchwith 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
UnionTypebd2eb4e because of these reasons (for now).