1
0
mirror of https://github.com/danog/psalm.git synced 2024-11-27 04:45:20 +01:00

Int and Float can be reconciled with Numeric (#5611)

This commit is contained in:
orklah 2021-04-10 05:59:59 +02:00 committed by GitHub
parent 3b3065c881
commit bb88cff28a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 23 additions and 0 deletions

View File

@ -1170,6 +1170,10 @@ class SimpleNegatedAssertionReconciler extends Reconciler
} 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;
}
@ -1261,6 +1265,10 @@ class SimpleNegatedAssertionReconciler extends Reconciler
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;
}

View File

@ -827,6 +827,21 @@ class RedundantConditionTest extends \Psalm\Tests\TestCase
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));
}
}'
]
];
}