1
0
mirror of https://github.com/danog/psalm.git synced 2024-11-30 04:39:00 +01:00

Merge pull request #9020 from orklah/isContainedbug

Is containedbug
This commit is contained in:
orklah 2022-12-28 23:46:38 +01:00 committed by GitHub
commit 9770e113c3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 4 deletions

View File

@ -75,7 +75,7 @@ class KeyedArrayComparator
$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,
@ -83,9 +83,8 @@ class KeyedArrayComparator
$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) {
@ -111,6 +110,9 @@ class KeyedArrayComparator
$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

View File

@ -2644,6 +2644,21 @@ class FunctionCallTest extends TestCase
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',
],
];
}