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
Parentheses in callable syntax are not interpreted correctly #74
Comments
That's nonsence. The syntax is ambigous, there cannot be a correct way to interpret it. Maybe related #18 (it was a long time ago, so I'm not 100 % sure) |
Also note that top-level parentheses always have no effect, i.e. |
Please check the f() and g() examples. I don't mind if parentheses are supported (even useless) or forbidden, but now it fails silently and phpstan is using in errors syntax which is not supported by phpstan parser. |
So the issue in how we print the type? |
And failing silently in case of not supported syntax. Ideally |
I don't understand.
I think ut's allowed mostly for |
I don't think so. |
Yes, that is correct, even though it can be confusing. What would you expect? Note that the parentheses here are useless.
|
One is closure which returns int|string or null, second is closure which returns int or string or null. In following example is expected closure which returns int|string or null and as such is the code treated. If it was the same, this code would not fail. Also thanks, just found another bug due to testing the |
Based on what? Is that you wish? Again parsing phpdoc-parser/tests/PHPStan/Parser/TypeParserTest.php Lines 611 to 620 in c37ba6f
|
I've run this through typescript (a: (() => number)|string) => {
if (typeof a === 'string') {
return;
}
const x:never = a;
} and it interprets |
Parentheses in callables in some cases create unexpected results, like
(Closure(): int|null)
changing to(Closure(): int)|null
https://phpstan.org/r/f0db1360-c01a-4884-8c17-1caa7d464852
The text was updated successfully, but these errors were encountered: