From bb88cff28a898046494f0d15d7791015e5089398 Mon Sep 17 00:00:00 2001 From: orklah Date: Sat, 10 Apr 2021 05:59:59 +0200 Subject: [PATCH] Int and Float can be reconciled with Numeric (#5611) --- .../Type/SimpleNegatedAssertionReconciler.php | 8 ++++++++ .../TypeReconciliation/RedundantConditionTest.php | 15 +++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/src/Psalm/Internal/Type/SimpleNegatedAssertionReconciler.php b/src/Psalm/Internal/Type/SimpleNegatedAssertionReconciler.php index 878111b32..dd593f18c 100644 --- a/src/Psalm/Internal/Type/SimpleNegatedAssertionReconciler.php +++ b/src/Psalm/Internal/Type/SimpleNegatedAssertionReconciler.php @@ -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; } diff --git a/tests/TypeReconciliation/RedundantConditionTest.php b/tests/TypeReconciliation/RedundantConditionTest.php index 92501bdcb..308b06d32 100644 --- a/tests/TypeReconciliation/RedundantConditionTest.php +++ b/tests/TypeReconciliation/RedundantConditionTest.php @@ -827,6 +827,21 @@ class RedundantConditionTest extends \Psalm\Tests\TestCase return false; }' ], + 'NumericCanBeNotIntOrNotFloat' => [ + '