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

PHPStan is very lenient about extraneous chars at the end of a @return #6299

Open
orklah opened this issue Jan 4, 2022 · 2 comments
Open

Comments

@orklah
Copy link
Contributor

orklah commented Jan 4, 2022

Bug report

PHPStan seems to stop parsing as soon as it has a consistent type and ignores the following chars as detected in composer/semver#128
While not a bug per se, it allows weird syntax to go undetected and can lead to serious issues in debugging (see snippet below)

Code snippet that reproduces the problem

https://phpstan.org/r/6a8372a5-0f20-4469-a134-0807a15d3e6c

Expected output

In the example below, a simple typo will lead to very unclear error. The type is not valid, but instead of complaining about it, PHPStan will report an error on the return 0; because it stopped reading the type before reaching |int

Note that this is not an issue in a @param because PHPStan expects the variable name at the end of the line

Thanks!

@ondrejmirtes
Copy link
Member

This is tricky because after a type is consumed by the parser, the rest is used as an optional description available in the AST.

Really don't know how to tackle this without a BC break. /cc @JanTvrdik

@JanTvrdik
Copy link
Contributor

Maybe require whitespace between type and description?

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

No branches or pull requests

3 participants