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

Redundant range checks for typed ints #9514

Open
weirdan opened this issue Mar 15, 2023 · 3 comments
Open

Redundant range checks for typed ints #9514

weirdan opened this issue Mar 15, 2023 · 3 comments

Comments

@weirdan
Copy link
Collaborator

weirdan commented Mar 15, 2023

https://psalm.dev/r/a7b57656ec

Both asserts should be redundant, as the property is typed, and thus the value is always PHP_INT_MIN <= $value <= PHP_INT_MAX

Refs #9499 (comment)

@psalm-github-bot
Copy link

I found these snippets:

https://psalm.dev/r/a7b57656ec
<?php
class C {
    public int $i = 0;
}

function f(C $c): void {
    assert($c->i <= PHP_INT_MAX);
    assert($c->i >= PHP_INT_MIN);
}
Psalm output (using commit 9b00049):

No issues!

@weirdan
Copy link
Collaborator Author

weirdan commented Mar 15, 2023

Ideally we should also catch this: https://psalm.dev/r/2bbda08bb8

@psalm-github-bot
Copy link

I found these snippets:

https://psalm.dev/r/2bbda08bb8
<?php
class C {
    public int $i = 0;
}

function f(C $c): void {
    $i = $c->i;
    assert($i <= PHP_INT_MAX);
    assert($i >= PHP_INT_MIN);
}
Psalm output (using commit 9b00049):

No issues!

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

No branches or pull requests

1 participant