Skip to content

Use bottom type for read/write-only properties #2328

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

Merged
merged 2 commits into from
Apr 5, 2023

Conversation

jtojnar
Copy link
Contributor

@jtojnar jtojnar commented Apr 5, 2023

Follow-up to #2327

It is not meaningful to return the writable type from getReadableType() type for non-readable properties.
Let’s return a bottom type to make it clear that no value can be read from the property.
And similarly, for non-writable properties, getReadableType() will return bottom type
to emphasize that no value exists that can be written to the property.

Probably best rebase-merge so that the second commit can be easily reverted if it turns out it causes too many issues.

Verified

This commit was signed with the committer’s verified signature.
ondrejmirtes Ondřej Mirtes
… readable types separately
@jtojnar jtojnar force-pushed the never-incorrect-type branch from 6acb312 to 880dc47 Compare April 5, 2023 10:52
Copy link
Member

@ondrejmirtes ondrejmirtes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please uncomment the test in tests/PHPStan/Analyser/data/classPhpDocs-phpstanPropertyPrefix.php

Verified

This commit was signed with the committer’s verified signature.
ondrejmirtes Ondřej Mirtes
…ad/write-only properties

It is not meaningful to return the writable type from getReadableType() type for non-readable properties.
Let’s return a bottom type to make it clear that no value can be read from the property.
And similarly, for non-writable properties, getReadableType() will return bottom type
to emphasize that no value exists that can be written to the property.
@jtojnar jtojnar force-pushed the never-incorrect-type branch from 880dc47 to 8ebee0b Compare April 5, 2023 11:00
@jtojnar
Copy link
Contributor Author

jtojnar commented Apr 5, 2023

Done.

@ondrejmirtes ondrejmirtes merged commit a8f2772 into phpstan:1.10.x Apr 5, 2023
@ondrejmirtes
Copy link
Member

Thank you!

@jtojnar jtojnar deleted the never-incorrect-type branch April 5, 2023 11:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants