1
0
mirror of https://github.com/danog/psalm.git synced 2025-01-22 05:41:20 +01:00

Allow float to be empty (0.00)

This commit is contained in:
Matt Brown 2018-09-10 15:38:31 -04:00
parent 334c463e08
commit 661087d445
2 changed files with 23 additions and 0 deletions

View File

@ -427,6 +427,23 @@ class Reconciler
}
}
if ($existing_var_type->hasFloat()) {
$existing_float_types = $existing_var_type->getLiteralFloats();
if ($existing_float_types) {
foreach ($existing_float_types as $key => $literal_type) {
if ($literal_type->value) {
$existing_var_type->removeType($key);
$did_remove_type = true;
}
}
} else {
$did_remove_type = true;
$existing_var_type->removeType('float');
$existing_var_type->addType(new Type\Atomic\TLiteralFloat(0));
}
}
if (isset($existing_var_atomic_types['array'])
&& $existing_var_atomic_types['array']->getId() !== 'array<empty, empty>'
) {

View File

@ -1042,6 +1042,12 @@ class TypeReconciliationTest extends TestCase
if (!$a || ($a instanceof B && $a->b())) {}
}',
],
'reconcileFloatToEmpty' => [
'<?php
function bar(float $f) : void {
if (!$f) {}
}',
],
];
}