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
Address flaw in type reconciliation on array references #8290
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains 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
This file contains 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
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.
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.
@AndrolGenhald I'm not sure whether this is enough, or
$existing_types[$referenced]
, or$referenced
value (e.g.'$doesNotMatter[$a]'
) should to be split to corresponding types of$doesNotMatter
+$a
and traversedThanks in advance for any hint.
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.
I'll step through it with your test tonight or tomorrow and see what's going on. Thanks for the reproduction and possible fix!
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.
Seems like it needs to have a type, I just ran into another error in a project having this patch applied:
psalm/src/Psalm/Context.php
Line 521 in a32e63f
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.
Oh, yeah, having nulls in there is not a good idea. I think I know what's going on though; when we do the check against
$a
it potentially changes$a
's type, which means we remove everything dependent on$a
fromContext::$vars_in_scope
(somewhere, can't remember where right now) because$doesNotMatter[$a]
doesn't have the same type if$a
has changed. When that happens, we also need to do something to any references that exist to$doesNotMatter[$a]
, probably by changing whatever code removes$doesNotMatter[$a]
to use the normal process by callingContext::remove()
instead of whatever it's doing now.Of course this means the fact that it's a reference will be lost, but like I said before, combining references with arrays and objects is just asking for trouble, and there's not much we can do about it.
Edit: oh, this is actually because it's removed from
$existing_types
in the same method further down, before it even gets to the context. Line 339 (and possibly 724) are where the issue is happening. I think it needs to do something sort of like Context:569-588, but probably a bit different using$reference_map
.