Skip to content

Commit

Permalink
Merge pull request #9439 from ptomulik/issue-9433
Browse files Browse the repository at this point in the history
Fix #9433
  • Loading branch information
orklah committed Mar 12, 2023
2 parents 44ffd5f + 84b389e commit 60a1389
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/Psalm/Internal/Type/TypeCombiner.php
Original file line number Diff line number Diff line change
Expand Up @@ -551,6 +551,8 @@ private static function scrapeTypeProperties(
}

foreach ($type->type_params as $i => $type_param) {
// See https://github.com/vimeo/psalm/pull/9439#issuecomment-1464563015
/** @psalm-suppress PropertyTypeCoercion */
$combination->array_type_params[$i] = Type::combineUnionTypes(
$combination->array_type_params[$i] ?? null,
$type_param,
Expand Down Expand Up @@ -599,6 +601,8 @@ private static function scrapeTypeProperties(

if ($type instanceof TClassStringMap) {
foreach ([$type->getStandinKeyParam(), $type->value_param] as $i => $type_param) {
// See https://github.com/vimeo/psalm/pull/9439#issuecomment-1464563015
/** @psalm-suppress PropertyTypeCoercion */
$combination->array_type_params[$i] = Type::combineUnionTypes(
$combination->array_type_params[$i] ?? null,
$type_param,
Expand Down
2 changes: 1 addition & 1 deletion src/Psalm/Type/Reconciler.php
Original file line number Diff line number Diff line change
Expand Up @@ -761,7 +761,7 @@ private static function getValueForKey(
return null;
}

$new_base_type_candidate = $existing_key_type_part->getGenericValueType();
$new_base_type_candidate = $existing_key_type_part->getGenericValueType(true);
} else {
$array_properties = $existing_key_type_part->properties;

Expand Down
19 changes: 19 additions & 0 deletions tests/TypeReconciliation/IssetTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1153,6 +1153,25 @@ private function __construct() {}
}',
'error_message' => 'RedundantPropertyInitializationCheck',
],
'setArbitraryListElementAfterIsset' => [
'code' => '<?php
/** @param list<string> $list */
function foo(array &$list, int $offset): void {
if (isset($list[$offset])) {}
$list[$offset] = "";
}',
'error_message' => 'ReferenceConstraintViolation',
],
'setArbitraryListWithinNotIsset' => [
'code' => '<?php
/** @param list<string> $list */
function foo(array &$list, int $offset): void {
if (!isset($list[$offset])) {
$list[$offset] = "";
}
}',
'error_message' => 'ReferenceConstraintViolation',
],
];
}
}

0 comments on commit 60a1389

Please sign in to comment.