-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[TypeInfo] Redesign Type methods and nullability #57630
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
Conversation
Using public properties instead of getters makes the maintenance harder in case we need to make the API of the component evolve (as we cannot rely on property hooks yet to implement BC layers) |
src/Symfony/Component/PropertyInfo/Extractor/PhpDocExtractor.php
Outdated
Show resolved
Hide resolved
1655aa6
to
a9cc6dd
Compare
be70dbe
to
d1d2368
Compare
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.
Loving all the changes ! 🚀
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.
In the current state of this PR, I'm voting -1 as it reduces the power of the component.
I am not sure I understand what problem your are trying to solve. A type is "just" a nullable type if Nevertheless, the changes feel a lot complex considering nullability is not a generic problem. There are only 3 kinds of nullable types: Therefore, I would only keep the current
With these little changes I believe nullability would be properly covered. |
@skalpa actually, there are more nullable types:
|
@stof, intersections cannot contain nullable types, only class/interface names, which is logical (nothing could be both an instance of For unions, yes, I meant "a union that contains a nullable" and not "a union that contains null", but after seeing your comment and checking, I believe it should be forbidden as well. Trying to add And a union cannot contain another union: this throws an exception ( |
@skalpa as said above, And why the PHP syntax enforces types to be written in disjunctive normal form (meaning no union inside intersection), I'm not sure TypeInfo should have this restriction on the created object graph (or it should have proper types enforcing valid usages). |
@stof, No, an intersection cannot contain While the normal form is something else, I really believe we should prevent the creation of nonsensical and/or invalid types that would never be satisfied by any value or would only result in PHP fatal errors if used, as they may probably be indicators of a bug in user code. If this is not enforced by the component, then as a user I will have to anticipate absolutely impossible cases just because the API allows them and I'd have to protect my code against intersections of scalars, or unions of (even though yes, technically you're right, any intersection is always equivalent to itself & mixed)
Some restrictions/enforcements are already there: you are not allowed to add a union to a union, or an intersection to another intersection, which is completely arbitrary if you consider that these could be merged later. But in fact I believe that @mtarld's is the right approach here and am just trying to build on top of it: IMHO, object graphs should be as canonical as possible. For instance, the fact that unions sort their subtypes is brilliant and without it, to compare To make this possible requires enforcing the normal form in the In return, If we consider that we should allow any random combination of types, then the current checks should be removed (but I would consider that a step back). TL;DR (sorry but I really like this component, I talk too much sometimes): I'd like to be able to assume that |
d1d2368
to
cc38917
Compare
Ok, I ended up with the following:
I'm still not sure if the Plus, I disallowed the creation of an WDYT? |
cc38917
to
5401c2c
Compare
5401c2c
to
61e49e7
Compare
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.
Better API
0e1e710
to
da9c58b
Compare
It looks like the tests are still failing. |
The high-deps build is failing because this PR purposely contains BC breaks as the component is experimental in 7.2. Failures will go away once this is merged. |
Indeed, tests will pass once merged. Then dependant components' tests will start failing on 7.1 as they will install type-info 7.2 so we will have to forbid it by adding conflict rules. |
The issue is that the conflict will lead to the fact that Composer may not install the latest 7.1 version of said component because of the conflict when 7.2 of the TypeInfo component is installed as we already have releases claiming to be compatible with TypeInfo 7.2. So the damage is already done. The only solution I see is to make the PropertyInfo component compatible with TypeInfo 7.2 as a bugfix in 7.1. In the future we need to be careful when adding requirements for experimental components and do not allow to install new minor versions of the from the beginning. |
@xabbuh a way to avoid that breakage is to make type-info conflict with older versions of those components, to workaround the fact that we used semver constraints for an experimental package not guaranteeing semver yet. |
Sounds good |
Indeed, @stof's suggestion is a good idea that we can use in this PR. |
da9c58b
to
d8db247
Compare
Yes, that a great idea, I just pushed that fix. |
3089f2d
to
75fce6f
Compare
75fce6f
to
8c376c8
Compare
@symfony/mergers Additional review needed to move forward before the component is considered stable. |
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.
Let's give this a try :)
Thank you @mtarld. |
This PR was merged into the 7.2 branch. Discussion ---------- [TypeInfo] tighten conflict rules | Q | A | ------------- | --- | Branch? | 7.2 | Bug fix? | no | New feature? | no | Deprecations? | no | Issues | Fix #57630 (comment) | License | MIT Commits ------- 87579c0 tighten conflict rules
…bility (mtarld) This PR was merged into the 7.1 branch. Discussion ---------- [PropertyInfo][Serializer][Validator] TypeInfo 7.2 compatibility | Q | A | ------------- | --- | Branch? | 7.1 | Bug fix? | yes | New feature? | no | Deprecations? | no | Issues | | License | MIT Make Serializer, PropertyInfo, and Validator components compatible with TypeInfo 7.2 breaking changes (#57630) so that we can remove the conflicts in TypeInfo's `composer.json` file in 7.2 Commits ------- 45d3ad2 [Serializer][PropertyInfo][Validator] TypeInfo 7.2 compatibility
By using the component and trying to integrate it within several libs, I ended up finding some limitations due to the component design.
Basically, the issues were:
Type
) knowing its concrete implementations (such as ingetBaseType
method).CollectionType
, andGenericType
are forwarding methods to their wrapped type using__call
, but I think this must be avoided as much as possible.To tackle these issues, I propose the following:
CompositeTypeInterface
andWrappingTypeInterface
that describe whether a type is composed by several types or wrapping one.NullableType
which extendsUnionType
and is aWrappingTypeInterface
, so that it is easy to recognize a nullable type and to get the non-nullable related type.Type::asNonNullable
method as it's covered byNullableType::getWrappedType
__call
method as it is easy to know it a type is wrapping another oneis
tosatisfy
and add the newCompositeTypeInterface::composedTypesSatisfy
andWrappingTypeInterface::wrappedTypeSatisfy
methodsisA
toisIdentifiedBy
Plus, thanks to @skalpa's great work, the following checks are added to prevent invalid type construction:
BackedEnumType
int
orstring
CollectionType
array
oriterable
when it's a built-in typeGenericType
array
oriterable
when it's a built-in typeIntersectionType
UnionType
UnionType
mixed
,void
, andnever
)true
andfalse
bool
andtrue
orfalse
object
and a class type