Skip to content

Commit

Permalink
handle cases where the classconst contains a compatible int type
Browse files Browse the repository at this point in the history
  • Loading branch information
orklah committed Jan 3, 2022
1 parent 6ea950c commit e3bb251
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions src/Psalm/Internal/Type/AssertionReconciler.php
Original file line number Diff line number Diff line change
Expand Up @@ -1266,15 +1266,13 @@ private static function handleLiteralEqualityWithInt(
): Union {
$value = (int) substr($assertion, $bracket_pos + 1, -1);

$existing_var_atomic_types = $existing_var_type->getAtomicTypes();

$compatible_int_type = self::getCompatibleIntType($existing_var_type, $value, $is_loose_equality);
if ($compatible_int_type !== null) {
return $compatible_int_type;
}

$has_int = false;

$existing_var_atomic_types = $existing_var_type->getAtomicTypes();
foreach ($existing_var_atomic_types as $existing_var_atomic_type) {
if ($existing_var_atomic_type instanceof TInt) {
$has_int = true;
Expand All @@ -1299,11 +1297,26 @@ private static function handleLiteralEqualityWithInt(
);

if ($expanded instanceof Atomic) {
$compatible_int_type = self::getCompatibleIntType($existing_var_type, $value, $is_loose_equality);
if ($compatible_int_type !== null) {
return $compatible_int_type;
}

if ($expanded instanceof TInt) {
$has_int = true;
}
} else {
foreach ($expanded as $expanded_type) {
$compatible_int_type = self::getCompatibleIntType(
$existing_var_type,
$value,
$is_loose_equality
);

if ($compatible_int_type !== null) {
return $compatible_int_type;
}

if ($expanded_type instanceof TInt) {
$has_int = true;
}
Expand Down

0 comments on commit e3bb251

Please sign in to comment.