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

handle literal equality with integer ranges

This commit is contained in:
orklah 2021-12-26 19:08:16 +01:00
parent 10226c1c58
commit d4fcb7f61c
2 changed files with 13 additions and 0 deletions

View File

@ -1026,6 +1026,7 @@ class AssertionReconciler extends Reconciler
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;

View File

@ -669,6 +669,18 @@ class IntRangeTest extends TestCase
'$length===' => 'int<1, 7>',
],
],
'literalEquality' => [
'<?php
/** @var string $secret */
$length = strlen($secret);
if ($length > 16) {
throw new exception("");
}
assert($length === 1);
',
],
];
}