Skip to content

Commit

Permalink
Merge pull request #9743 from klimick/fix-string-negation-to-never
Browse files Browse the repository at this point in the history
Fix string negation to never
  • Loading branch information
orklah committed May 4, 2023
2 parents fc233da + 948ece9 commit e809fb3
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/Psalm/Internal/Type/NegatedAssertionReconciler.php
Expand Up @@ -182,6 +182,10 @@ public static function reconcile(
) {
$existing_var_type->removeType('array-key');
$existing_var_type->addType(new TString);
} elseif ($assertion_type instanceof TNonEmptyString
&& $existing_var_type->hasString()
) {
// do nothing
} elseif ($assertion instanceof IsClassNotEqual) {
// do nothing
} elseif ($assertion_type instanceof TClassString && $assertion_type->is_loaded) {
Expand Down
26 changes: 26 additions & 0 deletions tests/AssertAnnotationTest.php
Expand Up @@ -2221,6 +2221,32 @@ function takesSomeIntFromEnum(int $foo): IntEnum
'ignored_issues' => [],
'php_version' => '8.1',
],
'assertStringIsNonEmptyString' => [
'code' => '<?php
/** @var string $str */;
/** @var string|int $stringOrInt */;
if (isNonEmptyString($str)) {
/** @psalm-check-type-exact $str = non-empty-string */;
} else {
/** @psalm-check-type-exact $str = string */;
}
if (isNonEmptyString($stringOrInt)) {
/** @psalm-check-type-exact $stringOrInt = non-empty-string */;
} else {
/** @psalm-check-type-exact $stringOrInt = string|int */;
}
/**
* @param mixed $_str
* @psalm-assert-if-true non-empty-string $_str
*/
function isNonEmptyString($_str): bool
{
return true;
}',
],
];
}

Expand Down

0 comments on commit e809fb3

Please sign in to comment.