From cbf7e596f75e9cf0e961a49917d10b34f804a419 Mon Sep 17 00:00:00 2001 From: Matt Brown Date: Mon, 14 Dec 2020 23:08:07 -0500 Subject: [PATCH] =?UTF-8?q?Fix=20#4827=20-=20don=E2=80=99t=20eradicate=20d?= =?UTF-8?q?ouble=20after=20int=20check?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Psalm/Internal/Type/AssertionReconciler.php | 7 ++++++- .../Type/Comparator/UnionTypeComparator.php | 5 +++-- tests/FunctionCallTest.php | 16 ++++++++++++++++ 3 files changed, 25 insertions(+), 3 deletions(-) diff --git a/src/Psalm/Internal/Type/AssertionReconciler.php b/src/Psalm/Internal/Type/AssertionReconciler.php index 39daf035d..9412ca7b6 100644 --- a/src/Psalm/Internal/Type/AssertionReconciler.php +++ b/src/Psalm/Internal/Type/AssertionReconciler.php @@ -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( diff --git a/src/Psalm/Internal/Type/Comparator/UnionTypeComparator.php b/src/Psalm/Internal/Type/Comparator/UnionTypeComparator.php index 867c51387..1474c1188 100644 --- a/src/Psalm/Internal/Type/Comparator/UnionTypeComparator.php +++ b/src/Psalm/Internal/Type/Comparator/UnionTypeComparator.php @@ -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 ); diff --git a/tests/FunctionCallTest.php b/tests/FunctionCallTest.php index e66fe3f3a..ea53d00bf 100644 --- a/tests/FunctionCallTest.php +++ b/tests/FunctionCallTest.php @@ -1406,6 +1406,22 @@ class FunctionCallTest extends TestCase [], '8.0' ], + 'getTypeDoubleThenInt' => [ + '