Skip to content

Commit

Permalink
Int and Float can be reconciled with Numeric (#5611)
Browse files Browse the repository at this point in the history
  • Loading branch information
orklah authored Apr 10, 2021
1 parent 3b3065c commit bb88cff
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/Psalm/Internal/Type/SimpleNegatedAssertionReconciler.php
Original file line number Diff line number Diff line change
Expand Up @@ -1170,6 +1170,10 @@ private static function reconcileInt(
} elseif ($existing_var_type->from_calculation) {
$non_int_types[] = new TFloat();
}
} elseif ($type instanceof TNumeric) {
$did_remove_type = true;
$non_int_types[] = new TString();
$non_int_types[] = new TFloat();
} else {
$non_int_types[] = $type;
}
Expand Down Expand Up @@ -1261,6 +1265,10 @@ private static function reconcileFloat(
if ($is_equality) {
$non_float_types[] = $type;
}
} elseif ($type instanceof TNumeric) {
$did_remove_type = true;
$non_float_types[] = new TString();
$non_float_types[] = new TInt();
} else {
$non_float_types[] = $type;
}
Expand Down
15 changes: 15 additions & 0 deletions tests/TypeReconciliation/RedundantConditionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -827,6 +827,21 @@ function test(string|int|float|bool $value): bool {
return false;
}'
],
'NumericCanBeNotIntOrNotFloat' => [
'<?php
/** @param mixed $a */
function a($a): void{
if (is_numeric($a)) {
assert(!is_float($a));
}
}
/** @param mixed $a */
function b($a): void{
if (is_numeric($a)) {
assert(!is_int($a));
}
}'
]
];
}

Expand Down

0 comments on commit bb88cff

Please sign in to comment.