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

Fix #4827 - don’t eradicate double after int check

This commit is contained in:
Matt Brown 2020-12-14 23:08:07 -05:00 committed by Daniil Gentili
parent 4416da85e7
commit cbf7e596f7
Signed by: danog
GPG Key ID: 8C1BE3B34B230CA7
3 changed files with 25 additions and 3 deletions

View File

@ -476,7 +476,12 @@ class AssertionReconciler extends \Psalm\Type\Reconciler
&& UnionTypeComparator::isContainedBy(
$codebase,
$existing_var_type,
$new_type
$new_type,
false,
false,
null,
false,
false
)
) {
self::triggerIssueForImpossible(

View File

@ -27,7 +27,8 @@ class UnionTypeComparator
bool $ignore_null = false,
bool $ignore_false = false,
?TypeComparisonResult $union_comparison_result = null,
bool $allow_interface_equality = false
bool $allow_interface_equality = false,
bool $allow_float_int_equality = true
) : bool {
if ($union_comparison_result) {
$union_comparison_result->scalar_type_match_found = true;
@ -108,7 +109,7 @@ class UnionTypeComparator
$input_type_part,
$container_type_part,
$allow_interface_equality,
true,
$allow_float_int_equality,
$atomic_comparison_result
);

View File

@ -1406,6 +1406,22 @@ class FunctionCallTest extends TestCase
[],
'8.0'
],
'getTypeDoubleThenInt' => [
'<?php
function safe_float(mixed $val): bool {
switch (gettype($val)) {
case "double":
case "integer":
return true;
// ... more cases omitted
default:
return false;
}
}',
[],
[],
'8.0'
],
];
}