Skip to content

Conversation

@gsteel
Copy link

@gsteel gsteel commented Dec 23, 2025

isMap should accept mixed or array<array-key, T>, not array<string, T>. If the input was array<string, T>, we wouldn't need to use Assert::isMap().

`isMap` should accept `mixed` or `array<array-key, T>`, not `array<string, T>`. If the input was `array<string, T>`, we wouldn't need to use `Assert::isMap()`.
@zerkms
Copy link
Contributor

zerkms commented Dec 23, 2025

Isn't mixed|array<array-key, T> === mixed?

@gsteel
Copy link
Author

gsteel commented Dec 23, 2025

The array<array-key, T> preserves the value type when it is asserted via @psalm-assert, so array<array-key, MyThing> becomes array<string, MyThing>

@zerkms
Copy link
Contributor

zerkms commented Dec 23, 2025

I guess it's implementation dependent (the static analysis tool), but yep, agree.

* @psalm-assert array<string, T> $array
*
* @param array<string, T> $array
* @param mixed|array<array-key, T> $array
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should just be mixed. As in, remove the @param declaration because the actual type is already mixed $array.

* @param array<string, T> $array
* @param mixed|array<array-key, T> $array
*
* @return array<string, T>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is incorrect, it should be @return array<array-key, T>.

*
* @template T
*
* @psalm-assert array<string, T> $array
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, this should be array<array-key, T>.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants