Skip to content

feat: support unions in arrays#1552

Open
simPod wants to merge 2 commits into
schmittjoh:masterfrom
simPod:union-arrays
Open

feat: support unions in arrays#1552
simPod wants to merge 2 commits into
schmittjoh:masterfrom
simPod:union-arrays

Conversation

@simPod
Copy link
Copy Markdown
Contributor

@simPod simPod commented Jul 19, 2024

Q A
Bug fix? no
New feature? yes
Doc updated no
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets #...
License MIT
  • The changes to the @type lexer/parser may support the simplest array<A|B> test case, but I can think of some edge cases that would cause that type parsing to fail. The @type typer lexer/parser currently has no union support, so this adds support for array<A|B> but there's no support for just A|B.
  • The only tests seem to be of the docblockparser (which is good), but no tests of any serialization/deserialization, no tests of the Type annotation lexer changes. + @simPod I think we need also E2E test of deserialisation - I think it should already work for simple types :)
  • What is the expected behaviour of A|B[] in a docblock type?

@simPod simPod force-pushed the union-arrays branch 3 times, most recently from 8ad44a6 to 00bfa52 Compare July 19, 2024 10:20
@scyzoryck
Copy link
Copy Markdown
Collaborator

@idbentley can you help with code review, please? :)

@scyzoryck
Copy link
Copy Markdown
Collaborator

@simPod I think we need also E2E test of deserialisation - I think it should already work for simple types :)

@idbentley
Copy link
Copy Markdown
Contributor

My main feedback is that this PR seems rather incomplete.

The changes to the @Type lexer/parser may support the simplest array<A|B> test case, but I can think of some edge cases that would cause that type parsing to fail. The @Type typer lexer/parser currently has no union support, so this adds support for array<A|B> but there's no support for just A|B.

The only tests seem to be of the docblockparser (which is good), but no tests of any serialization/deserialization, no tests of the Type annotation lexer changes.

What is the expected behaviour of A|B[] in a docblock type?

Overall, I think this is a great feature, but needs some extra help.

@simPod
Copy link
Copy Markdown
Contributor Author

simPod commented Feb 17, 2025

This is indeed rather incomplete. I'm now stuck with DeserializationGraphNavigator that does not know how to handle unions.

'params' => [
['name' => 'int', 'params' => []],
['name' => Product::class, 'params' => []],
['name' => Vehicle::class, 'params' => []],
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

@simPod It seems like array<int, string> and array<int|string> will create exactly the same metadata 😓 I would consider using Union pseudo type same as for the unions, so it will be handled by the Union Handler :D

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.

3 participants