Skip to content

Commit

Permalink
Merge pull request #9738 from klimick/fix-invalid-cast-for-templated-…
Browse files Browse the repository at this point in the history
…class-string

Fix invalid cast for templated class-string
  • Loading branch information
orklah committed May 4, 2023
2 parents 32bd8f6 + 57b3876 commit f8895ed
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/Psalm/Internal/Type/Comparator/ClassLikeStringComparator.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,24 @@ public static function isContainedBy(
: $input_type_part->value,
);

return AtomicTypeComparator::isContainedBy(
$isContainedBy = AtomicTypeComparator::isContainedBy(
$codebase,
$fake_input_object,
$fake_container_object,
$allow_interface_equality,
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;
}
}
13 changes: 13 additions & 0 deletions tests/FunctionCallTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
/**
Expand Down

0 comments on commit f8895ed

Please sign in to comment.