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

Regression: Docblock-defined type 0|int<1, 16> for $length is never int(1) #7223

Closed
kamil-tekiela opened this issue Dec 26, 2021 · 3 comments · Fixed by #7224
Closed

Regression: Docblock-defined type 0|int<1, 16> for $length is never int(1) #7223

kamil-tekiela opened this issue Dec 26, 2021 · 3 comments · Fixed by #7224

Comments

@kamil-tekiela
Copy link
Contributor

In the following example Docblock-defined type 0|int<1, 16> for $length is never int(1) the length can be between 0 and 15 which makes 1 a valid possibility. Psalm started to complain about it in the recent version.

Docblock-defined type 0|int<1, 16> for $length is never int(1)

@psalm-github-bot
Copy link

I found these snippets:

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

/** @var string $secret */
$length = strlen($secret);
if ($length > 16) {
    return substr($secret, 0, 16);
}

$length == 1 ? $secret : substr($secret, 0, -1);
Psalm output (using commit aa7e400):

ERROR: DocblockTypeContradiction - 9:1 - Docblock-defined type 0|int<1, 16> for $length is never int(1)

ERROR: RedundantConditionGivenDocblockType - 9:26 - Docblock-defined type 0|int<1, 16> for $length is never int(1)

ERROR: UnusedFunctionCall - 9:26 - The call to substr is not used

@orklah
Copy link
Collaborator

orklah commented Dec 26, 2021

I fixed only one side of the issue in #7224. The other side is technically a duplicate of #6871 but this is very not obvious so I'll keep that one open too.

As I said there: the other side, while easily fixed causes other false positives that I just don't know how to fix yet.

@orklah
Copy link
Collaborator

orklah commented Jan 28, 2022

This has been fixed in master branch and will be released in Psalm 5

@orklah orklah closed this as completed Jan 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants