1
0
mirror of https://github.com/danog/psalm.git synced 2025-01-21 21:31:13 +01:00

Merge pull request #9738 from klimick/fix-invalid-cast-for-templated-class-string

Fix invalid cast for templated class-string
This commit is contained in:
orklah 2023-05-04 18:43:41 +02:00 committed by GitHub
commit f8895edf4d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 25 additions and 1 deletions

View File

@ -80,7 +80,7 @@ class ClassLikeStringComparator
: $input_type_part->value,
);
return AtomicTypeComparator::isContainedBy(
$isContainedBy = AtomicTypeComparator::isContainedBy(
$codebase,
$fake_input_object,
$fake_container_object,
@ -88,5 +88,16 @@ class ClassLikeStringComparator
false,
$atomic_comparison_result,
);
if ($atomic_comparison_result
&& $atomic_comparison_result->replacement_atomic_type instanceof TNamedObject
) {
$atomic_comparison_result->replacement_atomic_type = new TClassString(
'object',
$atomic_comparison_result->replacement_atomic_type,
);
}
return $isContainedBy;
}
}

View File

@ -17,6 +17,19 @@ class FunctionCallTest extends TestCase
public function providerValidCodeParse(): iterable
{
return [
'callFunctionWithTemplateClassStringWillNotFail' => [
'code' => '<?php
/** @param class-string<SplFixedArray<string>> $classString */
function acceptTemplatedClassString(string $classString): void
{
}
/** @param class-string<SplFixedArray<string>> $classString */
function app(string $classString): void
{
acceptTemplatedClassString($classString);
}',
],
'inferGenericListFromTuple' => [
'code' => '<?php
/**