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

Assuming __LINE__ is int type #9811

Closed
brzuchal opened this issue May 23, 2023 · 6 comments
Closed

Assuming __LINE__ is int type #9811

brzuchal opened this issue May 23, 2023 · 6 comments
Labels
easy problems Issues that can be fixed without background knowledge of Psalm good first issue Help wanted

Comments

@brzuchal
Copy link

I presume a constant called __LINE__ will always be positive-int. Cannot imagine file line -1.
Here is an example of a failure https://psalm.dev/r/d81c91af5e

@psalm-github-bot
Copy link

I found these snippets:

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

/**
 * @param positive-int $i
 */
function line(int $i): int {
    return $i;
}
line(__LINE__)
Psalm output (using commit f90118c):

ERROR: ParseError - 9:15 - Syntax error, unexpected EOF on line 9

ERROR: ArgumentTypeCoercion - 9:6 - Argument 1 of line expects int<1, max>, but parent type int provided

@orklah
Copy link
Collaborator

orklah commented May 23, 2023

Seems legit :)

You can change this here:

Up for a PR?

@orklah orklah added easy problems Issues that can be fixed without background knowledge of Psalm Help wanted good first issue labels May 23, 2023
@brzuchal
Copy link
Author

Can try

@brzuchal
Copy link
Author

brzuchal commented May 24, 2023

@orklah I found 10 places where I could replace new TIntRange(1, null) with the newly introduced it'll be 11 - should I create a Type::getIntRange() and Type::getPositiveInt() helper methods?

@orklah
Copy link
Collaborator

orklah commented May 24, 2023

Yeah, please do :)

@weirdan
Copy link
Collaborator

weirdan commented Aug 21, 2023

Fixed in #9921

@weirdan weirdan closed this as completed Aug 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
easy problems Issues that can be fixed without background knowledge of Psalm good first issue Help wanted
Projects
None yet
Development

No branches or pull requests

3 participants