Skip to content

Commit

Permalink
Fix string negation to never
Browse files Browse the repository at this point in the history
  • Loading branch information
klimick committed May 4, 2023
1 parent fc233da commit 948ece9
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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 948ece9

Please sign in to comment.