Skip to content
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

Add has-property- assertion #9324

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

weirdan
Copy link
Collaborator

@weirdan weirdan commented Feb 17, 2023

On itself it doesn't do much good as property fetch analyzer doesn't
support object intersections yet. But it's a groundwork for future
enhancements.

@weirdan weirdan added the release:internal The PR will be included in 'Internal changes' section of the release notes label Feb 17, 2023
@weirdan weirdan requested a review from orklah February 17, 2023 06:21
On itself it doesn't do much good as property fetch analyzer doesn't
support object intersections yet. But it's a groundwork for future
enhancements.
@weirdan weirdan force-pushed the property-exists-assertion branch from 2055901 to 427045c Compare February 17, 2023 06:25
@orklah
Copy link
Collaborator

orklah commented Feb 22, 2023

Seems good. Calling isset on a property should probably create that assertion too (though it can't be reverted because the property could just be null or un-initialized)

@orklah
Copy link
Collaborator

orklah commented Feb 22, 2023

Does this fix #2206 and maybe #4182?

@weirdan
Copy link
Collaborator Author

weirdan commented Feb 22, 2023

though it can't be reverted

By the way, how do we make assertions that can't be inverted?

@weirdan
Copy link
Collaborator Author

weirdan commented Feb 22, 2023

Does this fix #2206 and maybe #4182

Not entirely. To fix those, we also need to fix property fetch analysis on intersections.

@orklah
Copy link
Collaborator

orklah commented Feb 22, 2023

By the way, how do we make assertions that can't be inverted?

In theory, it's mainly this: https://psalm.dev/docs/annotating_code/assertion_syntax/#equality-assertions

IsIdentical and IsLooselyEqual can't be meaningfully inverted whereas IsType can

But those only work with a specific type that must be given to the assertion. However, I found that we already have an isset assertion (but it doesn't seem to do much with properties). In fact, we have two: IsIsset and IsEqualIsset. The former can be inverted into IsNotIsset but the latter can't (trying to invert it will result in the "useless" assertion:

)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release:internal The PR will be included in 'Internal changes' section of the release notes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants