Skip to content

Commit

Permalink
Small assertion fix
Browse files Browse the repository at this point in the history
  • Loading branch information
danog committed Dec 7, 2023
1 parent 2ceb123 commit 48617f0
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions src/Psalm/Type/Reconciler.php
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ public static function reconcileKeyedTypes(
$has_negation = false;
$has_isset = false;
$has_inverted_isset = false;
$has_inverted_key_exists = false;
$has_truthy_or_falsy_or_empty = false;
$has_empty = false;
$has_count_check = false;
Expand Down Expand Up @@ -204,7 +205,9 @@ public static function reconcileKeyedTypes(
&& $new_type_part_part instanceof IsIdentical;

$has_inverted_isset = $has_inverted_isset
|| $new_type_part_part instanceof IsNotIsset
|| $new_type_part_part instanceof IsNotIsset;

$has_inverted_key_exists = $has_inverted_key_exists
|| $new_type_part_part instanceof ArrayKeyDoesNotExist;

$has_count_check = $has_count_check
Expand All @@ -224,6 +227,7 @@ public static function reconcileKeyedTypes(
$code_location,
$has_isset,
$has_inverted_isset,
$has_inverted_key_exists,
$has_empty,
$inside_loop,
$has_object_array_access,
Expand Down Expand Up @@ -337,7 +341,7 @@ public static function reconcileKeyedTypes(
if ($type_changed || $failed_reconciliation) {
$changed_var_ids[$key] = true;

if (str_ends_with($key, ']') && !$has_inverted_isset && !$has_empty && !$is_equality) {
if (str_ends_with($key, ']') && !$has_inverted_isset && !$has_inverted_key_exists && !$has_empty && !$is_equality) {
self::adjustTKeyedArrayType(
$key_parts,
$existing_types,
Expand Down Expand Up @@ -651,6 +655,7 @@ private static function getValueForKey(
?CodeLocation $code_location,
bool $has_isset,
bool $has_inverted_isset,
bool $has_inverted_key_exists,
bool $has_empty,
bool $inside_loop,
bool &$has_object_array_access,
Expand Down Expand Up @@ -724,11 +729,11 @@ private static function getValueForKey(

$new_base_type_candidate = $existing_key_type_part->type_params[1];

if ($new_base_type_candidate->isMixed() && !$has_isset && !$has_inverted_isset) {
if ($new_base_type_candidate->isMixed() && !$has_isset && !$has_inverted_isset && !$has_inverted_key_exists) {
return $new_base_type_candidate;
}

if (($has_isset || $has_inverted_isset) && isset($new_assertions[$new_base_key])) {
if (($has_isset || $has_inverted_isset || $has_inverted_key_exists) && isset($new_assertions[$new_base_key])) {
if ($has_inverted_isset && $new_base_key === $key) {
$new_base_type_candidate = $new_base_type_candidate->getBuilder();
$new_base_type_candidate->addType(new TNull);
Expand Down Expand Up @@ -757,7 +762,7 @@ private static function getValueForKey(
} elseif ($existing_key_type_part instanceof TString) {
$new_base_type_candidate = Type::getString();
} elseif ($existing_key_type_part instanceof TNamedObject
&& ($has_isset || $has_inverted_isset)
&& ($has_isset || $has_inverted_isset || $has_inverted_key_exists)
) {
$has_object_array_access = true;

Expand Down

0 comments on commit 48617f0

Please sign in to comment.