diff --git a/src/Psalm/Internal/Type/AssertionReconciler.php b/src/Psalm/Internal/Type/AssertionReconciler.php index c426694d959..e55661873aa 100644 --- a/src/Psalm/Internal/Type/AssertionReconciler.php +++ b/src/Psalm/Internal/Type/AssertionReconciler.php @@ -1026,6 +1026,7 @@ private static function handleLiteralEquality( foreach ($existing_var_atomic_types as $atomic_key => $atomic_type) { if ($atomic_key !== $assertion && !($atomic_type instanceof TPositiveInt && $value > 0) + && !($atomic_type instanceof TIntRange && $atomic_type->contains($value)) ) { $existing_var_type->removeType($atomic_key); $did_remove_type = true; diff --git a/tests/IntRangeTest.php b/tests/IntRangeTest.php index 8397ba1811b..5b7cf913eaf 100644 --- a/tests/IntRangeTest.php +++ b/tests/IntRangeTest.php @@ -669,6 +669,18 @@ function doAnalysis(): void '$length===' => 'int<1, 7>', ], ], + 'literalEquality' => [ + ' 16) { + throw new exception(""); + } + + assert($length === 1); + ', + ], ]; }