Skip to content

Commit

Permalink
handle literal equality with integer ranges
Browse files Browse the repository at this point in the history
  • Loading branch information
orklah committed Dec 26, 2021
1 parent db82095 commit 05b0635
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/Psalm/Internal/Type/AssertionReconciler.php
Expand Up @@ -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;
Expand Down
12 changes: 12 additions & 0 deletions tests/IntRangeTest.php
Expand Up @@ -669,6 +669,18 @@ function doAnalysis(): void
'$length===' => 'int<1, 7>',
],
],
'literalEquality' => [
'<?php
/** @var string $secret */
$length = strlen($secret);
if ($length > 16) {
throw new exception("");
}
assert($length === 1);
',
],
];
}

Expand Down

0 comments on commit 05b0635

Please sign in to comment.