Skip to content

Commit

Permalink
Merge pull request #9750 from klimick/fix-union-argument-type-check
Browse files Browse the repository at this point in the history
Fix union argument type check against templated param
  • Loading branch information
orklah committed May 6, 2023
2 parents 8d15fa1 + cfd0f06 commit c9e8b48
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Psalm/Internal/Type/TemplateStandinTypeReplacer.php
Original file line number Diff line number Diff line change
Expand Up @@ -585,7 +585,7 @@ private static function findMatchingAtomicTypesForTemplate(

if (!empty($classlike_storage->template_extended_params[$base_type->value])) {
$atomic_input_type = new TGenericObject(
$atomic_input_type->value,
$base_type->value,
array_values($classlike_storage->template_extended_params[$base_type->value]),
);

Expand Down
23 changes: 23 additions & 0 deletions tests/FunctionCallTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,29 @@ class FunctionCallTest extends TestCase
public function providerValidCodeParse(): iterable
{
return [
'callTemplatedFunctionWithUnionArgument' => [
'code' => '<?php
/** @template T */
interface Message {}
/** @implements Message<int> */
final class FirstMessage implements Message {}
/** @implements Message<int> */
final class SecondMessage implements Message {}
/**
* @template T
* @param Message<T> $msg
*/
function test(Message $msg): void {}
/** @var FirstMessage|SecondMessage $message */;
test($message);',
'assertions' => [],
'ignored_issues' => [],
'php_version' => '8.0',
],
'callFunctionWithTemplateClassStringWillNotFail' => [
'code' => '<?php
/** @param class-string<SplFixedArray<string>> $classString */
Expand Down

0 comments on commit c9e8b48

Please sign in to comment.