Skip to content

Commit

Permalink
Merge pull request #9020 from orklah/isContainedbug
Browse files Browse the repository at this point in the history
Is containedbug
  • Loading branch information
orklah committed Dec 28, 2022
2 parents 94f9d48 + a290729 commit 9770e11
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/Psalm/Internal/Type/Comparator/KeyedArrayComparator.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,17 +75,16 @@ public static function isContainedBy(
$property_type_comparison = new TypeComparisonResult();

if (!$input_property_type->isNever()) {
if (!UnionTypeComparator::isContainedBy(
$is_input_containedby_container = UnionTypeComparator::isContainedBy(
$codebase,
$input_property_type,
$container_property_type,
$input_property_type->ignore_nullable_issues,
$input_property_type->ignore_falsable_issues,
$property_type_comparison,
$allow_interface_equality,
)
&& !$property_type_comparison->type_coerced_from_scalar
) {
);
if (!$is_input_containedby_container && !$property_type_comparison->type_coerced_from_scalar) {
$inverse_property_type_comparison = new TypeComparisonResult();

if ($atomic_comparison_result) {
Expand All @@ -111,6 +110,9 @@ public static function isContainedBy(

$all_types_contain = false;
} else {
if (!$is_input_containedby_container) {
$all_types_contain = false;
}
if ($atomic_comparison_result) {
$atomic_comparison_result->to_string_cast
= $atomic_comparison_result->to_string_cast === true
Expand Down
15 changes: 15 additions & 0 deletions tests/FunctionCallTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2644,6 +2644,21 @@ function finalFunc() {
foo();',
'error_message' => 'InvalidReturnType',
],
'DontAcceptArrayWithShapesNotContained' => [
'code' => '<?php
/** @param array{bar: 0|positive-int} $foo */
function takesArrayShapeWithZeroOrPositiveInt(array $foo): void
{
}
/** @var int $mayBeInt */
$mayBeInt = -1;
takesArrayShapeWithZeroOrPositiveInt(["bar" => $mayBeInt]);
',
'error_message' => 'InvalidArgument',
],
];
}

Expand Down

0 comments on commit 9770e11

Please sign in to comment.