-
Notifications
You must be signed in to change notification settings - Fork 670
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
False positive NoValue #9349
Comments
I found these snippets: https://psalm.dev/r/f12fbc1db8<?php
$str = $argv[1] ?? '';
if(empty($str) || strlen($str) < 3) {
exit(1);
}
echo $str;
https://psalm.dev/r/a0bf807db5<?php
$str = $argv[1] ?? '';
if(strlen($str) < 3) {
exit(1);
}
echo $str;
|
Same with: <?php
class CodeReader
{
public function read(string $code): ?string
{
if (empty($code) || strlen($code) < 32) {
return null;
}
$code = substr($code, 3);
return $code;
}
} https://psalm.dev/r/a99bcc7c07 works without empty <?php
class CodeReader
{
public function read(string $code): ?string
{
if (strlen($code) < 32) {
return null;
}
$code = substr($code, 3);
return $code;
}
} https://psalm.dev/r/1fbf4fbcfc Error is shown in wrong line imho. Should be something like unnecessary |
I found these snippets: https://psalm.dev/r/a99bcc7c07<?php
class CodeReader
{
public function read(string $code): ?string
{
if (empty($code) || strlen($code) < 32) {
return null;
}
$code = substr($code, 3);
return $code;
}
}
https://psalm.dev/r/1fbf4fbcfc<?php
class CodeReader
{
public function read(string $code): ?string
{
if (strlen($code) < 32) {
return null;
}
$code = substr($code, 3);
return $code;
}
}
|
/cc: @LeoVie |
slighly different usecase with different error, but I guess underlying issue is the same |
I found these snippets: https://psalm.dev/r/01a80b3670<?php
function test(string $s): void {
if (!$s || strlen($s) !== 9) {
throw new Exception();
}
}
|
Here is another false-positive example: https://psalm.dev/r/b72669f3a0 |
I found these snippets: https://psalm.dev/r/b72669f3a0<?php
/** @var string $a */
if (strlen($a) === 7) {
return $a;
} elseif (strlen($a) === 10) {
return $a;
}
|
Thanks @jack-worman, this is probably the clearest example out of all posted here. With traces: https://psalm.dev/r/8b1462cca9 |
I found these snippets: https://psalm.dev/r/8b1462cca9<?php
/** @var string $a */
if (strlen($a) === 7) {
return $a;
} else {
/** @psalm-trace $a */;
if (strlen($a) === 10) {
return $a;
}
}
|
Hi.
Psalm 5.7.1
I got this error on a simple example.
https://psalm.dev/r/f12fbc1db8
The error disappeared when I removed the unnecessary "empty" check.
https://psalm.dev/r/a0bf807db5
The text was updated successfully, but these errors were encountered: