Open rzvc opened 2 years ago
I found these snippets:
I've noticed this too and thought it was intentional, but it does get confusing if the type is an array: https://psalm.dev/r/6b3ada442e
We also support ...$params
which I think is much clearer: https://psalm.dev/r/70fdeadbc2
I suppose we could change it like this for 5.0, but I'm not sure how much of an impact it would have on existing projects. If it's going to break a lot of stuff it doesn't seem worth it. Does the phpdoc documentation have anything to say about variadic arguments?
I found these snippets:
Regarding your allowedButNotPreferredDueToAmbiguity, I would like to stress how important it is that it continues to be allowed, because it makes things like this possible:
/**
* @param list<string> | array{ 0: PossiblyOtherShapeOrArrayType } $params
*/
This will also come in handy in the future when method overloading is implemented.
I think that just disallowing the /** @param string $params */
notation, will remove all the ambiguity and future confusion, because /** @param string[] $params */
correctly specifies the resulting type of the $params
variable, while /** @param string ...$params */
specifies the type of each individual item in the resulting $param
variable. It works.
Edit:
If it's going to break a lot of stuff it doesn't seem worth it.
Perhaps an opt-in into the old (broken) behavriour could be added for those cases.
Another one example: https://psalm.dev/r/8f74c8dc4e
I found these snippets:
@zlodes this is a separate issue, and can be fixed by adding a @no-named-arguments
annotation: https://psalm.dev/r/17620f76e6
I found these snippets:
The following two declarations result in the same type:
https://psalm.dev/r/738418eb4d
Edit: I suggest that only the second one to be considered valid, while the first one should issue an error.