-
Notifications
You must be signed in to change notification settings - Fork 650
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
str_pad, str_repeat and non-empty-strings #6049
Comments
I found these snippets: https://psalm.dev/r/c7f5c10980<?php
/**
* @param non-empty-string $foo
*/
function foo($foo) : void
{
echo $foo;
}
foo(str_pad('a', 100));
|
Actually it's or, not and |
@ciaranmcnulty does the following signature match your expectations: https://psalm.dev/r/ecdcca18ba ? |
I found these snippets: https://psalm.dev/r/ecdcca18ba<?php
/**
* @return ($_string is non-empty-string ? non-empty-string : ($_length is positive-int ? non-empty-string: string))
*/
function f(string $_string, int $_length): string {
return $_string; // to suppress the error
}
$_a = f("a", 0); /** @psalm-trace $_a */; // expected: non-empty-string
$_b = f("", 1); /** @psalm-trace $_b */; // expected: non-empty-string
$_c = f("", -1); /** @psalm-trace $_c */; // expected: string
|
It looks like there is some funny stuff when the length is less than the original string length too |
Got an example? |
Actually that looks fine. There's a third param but it doesn't affect the logic as it has to be a non-empty-string. str_repeat seems to have a very similar issue / solution |
Psalm does not know that str_pad is guaranteed to return a non-empty-string for certain inputs
https://psalm.dev/r/c7f5c10980
If the input is a non-empty-string and the padding is >0, this should always be the case
The text was updated successfully, but these errors were encountered: