Skip to content

Commit

Permalink
Merge pull request #9339 from edsrzf/is-numeric-negated
Browse files Browse the repository at this point in the history
  • Loading branch information
weirdan authored Feb 19, 2023
2 parents 863f15a + 38cc316 commit d934875
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/Psalm/Internal/Type/SimpleNegatedAssertionReconciler.php
Original file line number Diff line number Diff line change
Expand Up @@ -1292,6 +1292,10 @@ private static function reconcileNumeric(
} elseif ($type instanceof TArrayKey) {
$redundant = false;
$non_numeric_types[] = new TString();
} elseif ($type instanceof TScalar) {
$redundant = false;
$non_numeric_types[] = new TString();
$non_numeric_types[] = new TBool();
} elseif (!$type->isNumericType()) {
$non_numeric_types[] = $type;
} else {
Expand Down
14 changes: 14 additions & 0 deletions tests/TypeReconciliation/ConditionalTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,20 @@ function foo ($a) {
'$a' => 'string',
],
],
'typeRefinementonWithNegatedIsNumeric' => [
'code' => '<?php
/**
* @param scalar $v
* @return bool|string
*/
function toString($v)
{
if (is_numeric($v)) {
return false;
}
return $v;
}',
],
'typeRefinementWithStringOrTrue' => [
'code' => '<?php
$a = rand(0, 5) > 4 ? "hello" : true;
Expand Down

0 comments on commit d934875

Please sign in to comment.