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
literal strings as non-empty-string #5017
Labels
Comments
I found these snippets: https://psalm.dev/r/0cb0b9aa53<?php
/**
* @return list<non-empty-string>
*/
function a(): array
{
// Imaging I have a declared type like this:
/** @var array{foo?: list<non-empty-string>} $array */
$array = ['foo' => ['bar']];
return $array['foo'] ?? ['bar'];
}
|
Not necessarily. It's reconciliation between literal and non-empty strings that should result in non-empty string here, but that doesn't currently happen: https://psalm.dev/r/6d680d86b6 |
I found these snippets: https://psalm.dev/r/6d680d86b6<?php
/** @return non-empty-string */
function a()
{
/** @var non-empty-string */
$s = 'foo';
if (rand(0, 1)) {
$r = $s;
} else {
/** @psalm-trace $r */
$r = 'bar';
}
// expected non-empty-string, but Psalm infers it as string
/** @psalm-trace $r */;
return $r;
}
|
nvm |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Should literal strings be a
non-empty-string
?The problem I occurred is the following:
https://psalm.dev/r/0cb0b9aa53
The text was updated successfully, but these errors were encountered: