-
Notifications
You must be signed in to change notification settings - Fork 679
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
Concat should never remove "non-empty-"/"non-falsy-" from string #9411
Comments
I found these snippets: https://psalm.dev/r/0baa3234b5<?php
/**
* @param non-falsy-string $arg
* @return non-falsy-string
*/
function foo( $arg ) {
$result = FOO . $arg;
/** @psalm-trace $result */;
return $result;
}
|
It's handled here: psalm/src/Psalm/Internal/Analyzer/Statements/Expression/BinaryOp/ConcatAnalyzer.php Line 255 in 1c19260
It should be a pretty simple change |
The problem is more complex than it might seem. psalm/src/Psalm/Internal/Analyzer/Statements/Expression/BinaryOp/ConcatAnalyzer.php Line 65 in 1c19260
This variable is null for this snippets https://psalm.dev/r/f264a4732f https://psalm.dev/r/9ef452ff58 |
I found these snippets: https://psalm.dev/r/f264a4732f<?php
/**
* @param non-empty-string $arg
* @return non-empty-string
*/
function foo( $arg ) {
/** @psalm-suppress UndefinedConstant */
return FOO . $arg;
}
https://psalm.dev/r/9ef452ff58<?php
/**
* @param non-falsy-string $arg
* @return non-falsy-string
*/
function foo( $arg ) {
/** @psalm-suppress UndefinedConstant */
return FOO . $arg;
}
|
yeah, I guess it makes sense given FOO was not defined. Then psalm/src/Psalm/Internal/Analyzer/Statements/Expression/BinaryOp/ConcatAnalyzer.php Line 69 in 1c19260
|
#9422 I created pool request with fixes. But I newer worked with gihub pool requests. And I don't know how to link pool request to this issue. |
…emove-non-empty-non-falsy-from-string concat should never remove non empty non falsy from string #9411
https://psalm.dev/r/0baa3234b5
When concatenating a non-empty/non-falsy string with something else that is unknown (constants), the type should not "fall back", since it's wrong. And instead keep the type it already has (e.g. non-falsy-string in my example)
The text was updated successfully, but these errors were encountered: