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

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

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.

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

…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
Copy link
Contributor Author

jtojnar commented Apr 5, 2023

Done.

@ondrejmirtes ondrejmirtes merged commit a8f2772 into phpstan:1.10.x Apr 5, 2023
121 of 122 checks passed
@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
2 participants