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

Fix nullable union type identifier lazy load #991

Merged

Conversation

deguif
Copy link
Contributor

@deguif deguif commented Sep 28, 2022

Currently using union type for identifiers method doesn't permit to lazy load the entity.

With this fix, only a union type for a single type and null is supported. null can be at first position or at last.

For example:

This will enable lazy-loading (which previously was not):

public function getId(): int|null;
public function getId(): null|int;
public function getId(): \stdClass|null;
public function getId(): RelativeNamespace\Class|null;
public function getId(): \AbsoluteNamespace\Class|null;

@malarzm
Copy link
Member

malarzm commented Sep 28, 2022

Quick question as I haven't parsed the regex in my head yet: isn't this true for any unions and intersections?

@deguif
Copy link
Contributor Author

deguif commented Sep 28, 2022

isn't this true for any unions and intersections?

Current implementation only generate lazy loading identifier proxy for a single return type, which can be null. Is your question about supporting something like that?

public function getId(): int|string|...|null
{
     return $this->id;
}

For intersection they are not supported by the regex, do you mean it could be supported?

@malarzm
Copy link
Member

malarzm commented Sep 28, 2022

For intersection they are not supported by the regex, do you mean it could be supported?

Yes. Instead of extra support for |null we could introduce full support for any and all unions (and intersections while we're at it). I understand that |null will be the most common union used but if it would turn out not to be a big deal, then awesome :)

@deguif deguif force-pushed the fix-nullable-union-type-identifier-lazy-load branch from 48b2471 to ce8ef95 Compare September 28, 2022 18:33
@deguif
Copy link
Contributor Author

deguif commented Sep 28, 2022

@malarzm I added support for union and intersection type.

@malarzm
Copy link
Member

malarzm commented Sep 28, 2022

@deguif that's awesome! Would you mind adding a test for intersection as well?

@malarzm malarzm added the Bug label Sep 28, 2022
@malarzm malarzm added this to the 3.4.3 milestone Sep 28, 2022
@deguif deguif force-pushed the fix-nullable-union-type-identifier-lazy-load branch 5 times, most recently from 87618fa to 941b370 Compare September 29, 2022 09:47
@deguif
Copy link
Contributor Author

deguif commented Sep 29, 2022

PHPStan is complaining about the union with intersection type (for PHP 8.2). This should be fixed with the next release, as the reflection classes were updated to support union type with intersection type.

@deguif deguif force-pushed the fix-nullable-union-type-identifier-lazy-load branch 5 times, most recently from 4a0bc67 to 1809be6 Compare October 4, 2022 16:03
@deguif
Copy link
Contributor Author

deguif commented Oct 4, 2022

@malarzm tests are green now.
PHPStan 1.8.7 was released today, which allows the test for PHP 8.2 for union type with intersection type to success.

@deguif deguif force-pushed the fix-nullable-union-type-identifier-lazy-load branch from 1809be6 to a24b5fe Compare October 4, 2022 16:10
@deguif deguif force-pushed the fix-nullable-union-type-identifier-lazy-load branch 2 times, most recently from c7b5c4e to 0b88bb5 Compare October 4, 2022 16:25
@deguif deguif force-pushed the fix-nullable-union-type-identifier-lazy-load branch from 0b88bb5 to c67273f Compare October 4, 2022 16:34
@deguif deguif force-pushed the fix-nullable-union-type-identifier-lazy-load branch from c67273f to c187105 Compare October 4, 2022 16:47
@malarzm
Copy link
Member

malarzm commented Oct 4, 2022

Amazing, thanks you very much for changes and clean history! 🍻 I'll try to review/merge/release this week

@malarzm malarzm merged commit 8b5e565 into doctrine:3.4.x Oct 9, 2022
@malarzm
Copy link
Member

malarzm commented Oct 9, 2022

Thanks @deguif!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants