1
0
mirror of https://github.com/danog/psalm.git synced 2024-11-27 12:55:26 +01:00

Merge pull request #7224 from orklah/7223

handle literal equality with integer ranges
This commit is contained in:
orklah 2021-12-26 22:18:37 +01:00 committed by GitHub
commit 52ab139d2f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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);
',
],
];
}