1
0
mirror of https://github.com/danog/psalm.git synced 2025-01-22 05:41:20 +01:00

Fix faulty comparison with typed closure

This commit is contained in:
Matthew Brown 2021-12-16 16:39:08 +00:00
parent 84d677738e
commit 89a1c5acbc
2 changed files with 22 additions and 30 deletions

View File

@ -165,42 +165,26 @@ class AtomicTypeComparator
);
}
if ($container_type_part instanceof TClosure && $input_type_part instanceof TCallable) {
if (CallableTypeComparator::isContainedBy(
$codebase,
$input_type_part,
$container_type_part,
$atomic_comparison_result
) === false
) {
return false;
}
if ($container_type_part instanceof TClosure) {
if ($input_type_part instanceof TCallable) {
if (CallableTypeComparator::isContainedBy(
$codebase,
$input_type_part,
$container_type_part,
$atomic_comparison_result
) === false
) {
return false;
}
if ($atomic_comparison_result) {
$atomic_comparison_result->type_coerced = true;
if ($atomic_comparison_result) {
$atomic_comparison_result->type_coerced = true;
}
}
return false;
}
if ($container_type_part instanceof TClosure) {
if (!$input_type_part instanceof TClosure) {
if ($atomic_comparison_result) {
$atomic_comparison_result->type_coerced = true;
$atomic_comparison_result->type_coerced_from_mixed = true;
}
return false;
}
return CallableTypeComparator::isContainedBy(
$codebase,
$input_type_part,
$container_type_part,
$atomic_comparison_result
);
}
if ($container_type_part instanceof TCallable && $input_type_part instanceof TClosure) {
return CallableTypeComparator::isContainedBy(
$codebase,

View File

@ -1043,6 +1043,14 @@ class ClosureTest extends TestCase
false,
'7.4'
],
'closureInvalidArg' => [
'<?php
/** @param Closure(int): string $c */
function takesClosure(Closure $c): void {}
takesClosure(5);',
'error_message' => 'InvalidArgument',
],
];
}
}