-
Notifications
You must be signed in to change notification settings - Fork 653
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
Misparse of enums in list{} #10669
Comments
I found these snippets: https://psalm.dev/r/04fcfb0955<?php
enum A {
case X;
case Y;
case Z;
}
/**
* @return list{A::X|A::Y}
*/
function returnsList(int $c): array {
if ($c) {
return [A::X];
}
return [A::Y];
}
|
Just wrap the parts: https://psalm.dev/r/61d2d0ec1c |
I found these snippets: https://psalm.dev/r/61d2d0ec1c<?php
enum A {
case X;
case Y;
case Z;
}
/**
* @return list{(A::X)|(A::Y)}
*/
function returnsList(int $c): array {
if ($c) {
return [A::X];
}
return [A::Y];
}
|
@danog That seems rather like a workaround than a fix - I think it should stay open? I see no particular parse conflict here, why it should not be possible to parse that? |
Yeah that can be fixed! |
The reason for not allowing constants in list keys seems to be somewhat technical. Our type AST for keyed arrays uses native php types (int/string) to represent shape keys (they become actual array kes of But we should be able to support constants in list value types by backtracking and reinterpreting the part being parsed, as a value type, the same way we can do it currently with |
https://psalm.dev/r/04fcfb0955
While
@return A::X|A::Y
standalone works, putting it in alist{}
will misinterpret the first part of the expression up to the first colon as array key of the list instead of recognizing the enum value.The text was updated successfully, but these errors were encountered: