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

Invalid InvalidScalarArgument for uksort when used within a namespace #2847

Closed
azjezz opened this issue Feb 19, 2020 · 3 comments
Closed

Invalid InvalidScalarArgument for uksort when used within a namespace #2847

azjezz opened this issue Feb 19, 2020 · 3 comments
Labels

Comments

@azjezz
Copy link
Contributor

azjezz commented Feb 19, 2020

code :

<?php

declare(strict_types=1);

namespace Psl\Arr;

/**
 * @psalm-template Tk of array-key
 * @psalm-template Tv
 *
 * @psalm-param array<Tk, Tv> $iterable
 * @psalm-param (callable(Tk, Tk): int) $comparator
 *
 * @psalm-return array<Tk, Tv>
 */
function sort_by_key(array $iterable, callable $comparator): array
{
    $result = $iterable;
    \uksort($result, $comparator);
    return $result;
}

error :

Psalm output (using commit 306ed07):

ERROR: InvalidScalarArgument - 19:22 - Argument 2 of uksort expects callable(array-key, array-key):int, callable(Tk:fn-psl\arr\sort_by_key as array-key, Tk:fn-psl\arr\sort_by_key as array-key):int provided

snippet : https://psalm.dev/r/db79f4c93f

removing the namespace resolves the issue ( by definitely not a solution ) : https://psalm.dev/r/ee95831404

@psalm-github-bot
Copy link

I found these snippets:

https://psalm.dev/r/db79f4c93f
<?php

declare(strict_types=1);

namespace Psl\Arr;

/**
 * @psalm-template Tk of array-key
 * @psalm-template Tv
 *
 * @psalm-param array<Tk, Tv> $iterable
 * @psalm-param (callable(Tk, Tk): int) $comparator
 *
 * @psalm-return array<Tk, Tv>
 */
function sort_by_key(array $iterable, callable $comparator): array
{
    $result = $iterable;
    \uksort($result, $comparator);
    return $result;
}
Psalm output (using commit 306ed07):

ERROR: InvalidScalarArgument - 19:22 - Argument 2 of uksort expects callable(array-key, array-key):int, callable(Tk:fn-psl\arr\sort_by_key as array-key, Tk:fn-psl\arr\sort_by_key as array-key):int provided
https://psalm.dev/r/ee95831404
<?php

declare(strict_types=1);

/**
 * @psalm-template Tk of array-key
 * @psalm-template Tv
 *
 * @psalm-param array<Tk, Tv> $iterable
 * @psalm-param (callable(Tk, Tk): int) $comparator
 *
 * @psalm-return array<Tk, Tv>
 */
function sort_by_key(array $iterable, callable $comparator): array
{
    $result = $iterable;
    \uksort($result, $comparator);
    return $result;
}
Psalm output (using commit 306ed07):

No issues!

@muglug muglug added the bug label Feb 19, 2020
@muglug muglug closed this as completed in f4485cc Feb 21, 2020
@muglug
Copy link
Collaborator

muglug commented Feb 21, 2020

Sorry, this was a dumb bug

@azjezz
Copy link
Contributor Author

azjezz commented Feb 21, 2020

🎉 Thanks for the quick fix ❤️

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