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

Asymmetric @property types - thinner version #2327

Merged
merged 7 commits into from
Apr 5, 2023
Merged

Conversation

ondrejmirtes
Copy link
Member

@ondrejmirtes ondrejmirtes commented Apr 5, 2023

@ondrejmirtes ondrejmirtes merged commit 048b53f into 1.10.x Apr 5, 2023
52 checks passed
@ondrejmirtes ondrejmirtes deleted the asymmetric branch April 5, 2023 09:45
Comment on lines +13 to +14
private ?Type $readableType,
private ?Type $writableType,
Copy link
Contributor

Choose a reason for hiding this comment

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

One downside compared to #2294 is that sharing PropertyTag makes it impossible to e.g. inherit @property definition and then override @property-write in the subclass. (Though I did not bother implementing it yet.)

{
assertType('int', $this->asymmetricPropertyRw);
assertType('int', $this->asymmetricPropertyXw);
assertType('int|string', $this->asymmetricPropertyRx);
Copy link
Contributor

Choose a reason for hiding this comment

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

This does not look right. The @property should be shadowed by @property-read.

Copy link
Member Author

Choose a reason for hiding this comment

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

To me it doesn't make sense to allow both @property and @property-read. My expectation is that @property overwrites everything.

Copy link
Contributor

Choose a reason for hiding this comment

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

I would expect the opposite – the more specific @property-read and @property-write should overwrite the less specific @property (at least within the context of a single class). In fact, that was the behaviour before this PR.

Copy link
Member Author

Choose a reason for hiding this comment

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

Oh, please send an updating PR that restores this behaviour, and adds some tests for it. Thank you!

Copy link
Contributor

Choose a reason for hiding this comment

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

I do not care that much either way – converting my existing @property tags to @property-read when adding @property-write tags is only mildly annoying. Though, if we are counter-intuitively ignoring the more specific tags, we might want to add a check that warns that there are conflicting tags.

Copy link
Member Author

Choose a reason for hiding this comment

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

Because the tags are indexed by name, the check cannot really easily be written.

Copy link
Member Author

Choose a reason for hiding this comment

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

But backward compatibility is important to me so please research it and send a PR.

Copy link
Contributor

Choose a reason for hiding this comment

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

Opened #2329.

return new AnnotationPropertyReflection(
$declaringClass,
TemplateTypeHelper::resolveTemplateTypes(
$propertyTags[$propertyName]->getType(),
$propertyTag->getReadableType() ?? $defaultType,
Copy link
Contributor

Choose a reason for hiding this comment

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

Another point of difference from #2294, this will continue to return an incorrect readable type when the property is not readable. It would be more elegant if we used VoidType as the fallback type – then instead of checking if the property is readable/writeable and checking if a value can inhabit the type, we could simply check the value, since void is a bottom type that cannot be inhabited by any value.

Copy link
Member Author

Choose a reason for hiding this comment

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

That's NeverType, not VoidType. Yeah, I didn't understand that change. Feel free to update that scenario to NeverType, thank you.

Copy link
Contributor

Choose a reason for hiding this comment

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

Opened #2328.

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