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

Allow new lines in between declarations and also allow multiline union and intersection definition for array shapes #263

Conversation

DaDeather
Copy link
Contributor

@DaDeather DaDeather commented Feb 11, 2025

Takes care of:

@DaDeather DaDeather force-pushed the 258-allow-new-lines-inbetween-type-declarations branch 2 times, most recently from 8cdeba3 to e7ef350 Compare February 11, 2025 13:50
@DaDeather DaDeather force-pushed the 258-allow-new-lines-inbetween-type-declarations branch from e7ef350 to 122bb31 Compare February 11, 2025 15:33
$isFirst
|| $tokens->tryConsumeTokenType(Lexer::TOKEN_COMMA)
|| $tokens->tryConsumeTokenType(Lexer::TOKEN_UNION)
|| $tokens->tryConsumeTokenType(Lexer::TOKEN_INTERSECTION)
Copy link
Member

Choose a reason for hiding this comment

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

This doesn't make sense to me. The code makes it look like | and & could be used in place of , in a generic type.

Copy link
Member

Choose a reason for hiding this comment

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

Feel free to remove this part from the PR and submit it separately, the rest is solid.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You're totally right it was totally the wrong place.

I moved it accordingly and also adjusted the tests which if I would have had a better look would have already made clear that the parsed information would therefore be wrong 🙈.

I had to adjust the TypeParser::parse by using savepoints to check whether the union &/ intersection is valid to when being parsed to rollback when somethings feels off due to the information outputted afterwards not being shown "right".

So e.g. parsing /** @return A & B | C */ would had shown a error with partial information missing the beginning showing off a & B | C instead. (applied on test case invalid with type and disallowed description start token (2))

So if you by any chance have a better idea or solution to making this happen I'd be happy about any improvement here.

Otherwise this should now fulfill it's purpose allowing multiline type declarations and other multiline operations that may have led to an error before as stated with the tests and the linked issues that this would solve.

Let me know or feel free to make adjustments yourself if there's something we should do here 👍.

Otherwise thanks for the effort you're putting into all of this ❤️!

…r place and handle them
@DaDeather DaDeather force-pushed the 258-allow-new-lines-inbetween-type-declarations branch from 6ff8fc0 to 61ead7b Compare February 12, 2025 15:53
@ondrejmirtes ondrejmirtes merged commit 72e51f7 into phpstan:2.0.x Feb 13, 2025
43 of 44 checks passed
@ondrejmirtes
Copy link
Member

Nice, thank you!

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.

None yet

2 participants