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

psalm-assert: array<array-key, mixed> is always non-empty-array<array-key, mixed> #11321

Open
davidrans opened this issue Feb 19, 2025 · 1 comment
Labels

Comments

@davidrans
Copy link

There seems to be a mistake somewhere about non-empty-array<mixed> being more general than array<mixed>. Possibly related to psalm-assert?

See: https://psalm.dev/r/86465e1208

Copy link

I found these snippets:

https://psalm.dev/r/86465e1208
<?php

function getTemplateVariables(array $arr): void {
    exceptionIfEmpty($arr);
}

/**
 * @psalm-assert non-empty-array $things
 */
function exceptionIfEmpty(array $things): void {
   if (!$things) {
      throw new Exception("headEx() called on an empty array");
   }
}
Psalm output (using commit a9e6444):

ERROR: RedundantCondition - 4:5 - Type array<array-key, mixed> for $arr is always non-empty-array<array-key, mixed>

@orklah orklah added the bug label Feb 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants