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:
commit
52ab139d2f
@ -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;
|
||||
|
@ -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);
|
||||
',
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user