phpstan / phpdoc-parser

Next-gen phpDoc parser with support for intersection types and generics
MIT License
1.34k stars 61 forks source link

Return type in `@method` starting with `static` cannot be parsed #229

Closed mvorisek closed 8 months ago

mvorisek commented 8 months ago

Bug report

I know the current workaround is to place parenthesis around the return type, but this is problematic, as almost every CS fixer removes the parenthesis.

Like \Closure(): void, ie. type even with space is supported [1], unioned (and intersected) types should be supported as well.

[1] https://phpstan.org/r/e9b294c3-2f5f-42a1-b4a7-c2ad93a83c2f

Code snippet that reproduces the problem

https://phpstan.org/r/ad8c4bfc-4c57-48fc-838e-fc3d14a6d491

Expected output

no phpstan parser error

mvorisek commented 8 months ago

https://github.com/phpstan/phpdoc-parser/blob/1.25.0/doc/grammars/phpdoc-method.peg#L11 grammar already allows in as defined in https://github.com/phpstan/phpdoc-parser/blob/1.25.0/doc/grammars/type.abnf#L6

I wonder why the method grammar files are named *.peg instead of *.abnf and if fuzzed/tested.

JanTvrdik commented 8 months ago

That has nothing to do with the type being union. It because it's a grammar conflict with static methods.

So for example, if you could use any of the following, it works just fine:

JanTvrdik commented 8 months ago

I tried improving the conflict resolution logic we use: https://github.com/phpstan/phpdoc-parser/pull/230

mvorisek commented 8 months ago

Jan, thank you!

ondrejmirtes commented 8 months ago

Implemented https://github.com/phpstan/phpdoc-parser/pull/230

github-actions[bot] commented 7 months ago

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.