Skip to content

Fix return type of Ds\Sequence#copy()#1954

Merged
ondrejmirtes merged 3 commits intophpstan:1.10.xfrom
MidnightDesign:ds-copy
Feb 25, 2023
Merged

Fix return type of Ds\Sequence#copy()#1954
ondrejmirtes merged 3 commits intophpstan:1.10.xfrom
MidnightDesign:ds-copy

Conversation

@MidnightDesign
Copy link
Copy Markdown
Contributor

@MidnightDesign MidnightDesign commented Nov 3, 2022

I don't know why the return type isn't correctly inferred. It seems fine to me. Any ideas?

Playground link

@MidnightDesign MidnightDesign changed the title Fix return types of copy() methods in Ds\* Fix return type of Ds\Sequence#copy() Nov 3, 2022
@ondrejmirtes
Copy link
Copy Markdown
Member

The method probably isn't declared on Sequence. The correct solution might be to write @return static above Collection::copy().

@MidnightDesign
Copy link
Copy Markdown
Contributor Author

I've tried removing copy() from Sequence and making the return type of Collection static<TKey, TValue>, but that didn't change anything. I think it can't work because Collection takes two type arguments, and Sequence takes just one. I have no idea how to fix this.

@ondrejmirtes
Copy link
Copy Markdown
Member

Try just static

@MidnightDesign
Copy link
Copy Markdown
Contributor Author

You're right, that works. Thank you for your help!

@MidnightDesign MidnightDesign marked this pull request as ready for review November 4, 2022 10:03
@phpstan-bot
Copy link
Copy Markdown
Collaborator

This pull request has been marked as ready for review.

@ondrejmirtes ondrejmirtes merged commit 8cb3334 into phpstan:1.10.x Feb 25, 2023
@ondrejmirtes
Copy link
Copy Markdown
Member

Thank you!

@MidnightDesign MidnightDesign deleted the ds-copy branch February 26, 2023 18:33
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