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

0 + 1 positive-int ArgumentTypeCoercion #4081

Closed
vudaltsov opened this issue Aug 28, 2020 · 4 comments
Closed

0 + 1 positive-int ArgumentTypeCoercion #4081

vudaltsov opened this issue Aug 28, 2020 · 4 comments
Labels

Comments

@vudaltsov
Copy link
Contributor

https://psalm.dev/r/f1f013e2b5

@psalm-github-bot
Copy link

I found these snippets:

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

$tick = 0;

test($tick + 1);

test(0 + 1);

/**
 * @psalm-param positive-int $tickedTimes
 */
function test(int $tickedTimes): void
{
}
Psalm output (using commit fc50dd3):

ERROR: ArgumentTypeCoercion - 5:6 - Argument 1 of test expects positive-int, parent type int provided

ERROR: ArgumentTypeCoercion - 7:6 - Argument 1 of test expects positive-int, parent type int provided

INFO: UnusedParam - 12:19 - Param $tickedTimes is never referenced in this method

@muglug
Copy link
Collaborator

muglug commented Aug 28, 2020

Do you have a real-world example?

@vudaltsov
Copy link
Contributor Author

vudaltsov commented Aug 28, 2020

Do you have a real-world example?

https://psalm.dev/r/93ac6549b2

@psalm-github-bot
Copy link

psalm-github-bot bot commented Aug 28, 2020

I found these snippets:

https://psalm.dev/r/93ac6549b2
<?php

$i = 0;

for ($j = 0; $j < random_int(0, 100); $j++) {
    // do smth that needs a zero-based index $i
    
    ++$i;
}

notifyHowManyOperationsItTook($i + 1);

/**
 * @psalm-param positive-int $times
 */
function notifyHowManyOperationsItTook(int $times): void
{
}
Psalm output (using commit d29620a):

ERROR: ArgumentTypeCoercion - 11:31 - Argument 1 of notifyHowManyOperationsItTook expects positive-int, parent type int provided

INFO: UnusedParam - 16:44 - Param $times is never referenced in this method

@muglug muglug added the bug label Aug 28, 2020
@muglug muglug closed this as completed in df0d426 Aug 28, 2020
danog pushed a commit to danog/psalm that referenced this issue Jan 29, 2021
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