Skip to content

Commit

Permalink
Merge pull request #10586 from klimick/fix-template-replacement
Browse files Browse the repository at this point in the history
Fix template replacement edge case
  • Loading branch information
orklah committed Jan 24, 2024
2 parents 9616b14 + c307bcb commit 25b07fb
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 2 deletions.
2 changes: 0 additions & 2 deletions src/Psalm/Internal/Type/TemplateStandinTypeReplacer.php
Original file line number Diff line number Diff line change
Expand Up @@ -1254,7 +1254,6 @@ public static function getMappedGenericTypeParams(
Atomic $container_type_part,
?array &$container_type_params_covariant = null
): array {
$_ = null;
if ($input_type_part instanceof TGenericObject || $input_type_part instanceof TIterable) {
$input_type_params = $input_type_part->type_params;
} elseif ($codebase->classlike_storage_provider->has($input_type_part->value)) {
Expand Down Expand Up @@ -1290,7 +1289,6 @@ public static function getMappedGenericTypeParams(
$replacement_templates = [];

if ($input_template_types
&& (!$input_type_part instanceof TGenericObject || !$input_type_part->remapped_params)
&& (!$container_type_part instanceof TGenericObject || !$container_type_part->remapped_params)
) {
foreach ($input_template_types as $template_name => $_) {
Expand Down
62 changes: 62 additions & 0 deletions tests/Template/FunctionTemplateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,68 @@ class FunctionTemplateTest extends TestCase
public function providerValidCodeParse(): iterable
{
return [
'extractTypeParameterValue' => [
'code' => '<?php
/**
* @template T
*/
interface Type {}
/**
* @implements Type<int>
*/
final readonly class IntType implements Type {}
/**
* @template T
* @implements Type<list<T>>
*/
final readonly class ListType implements Type
{
/**
* @param Type<T> $type
*/
public function __construct(
public Type $type,
) {
}
}
/**
* @template T
* @param Type<T> $type
* @return T
*/
function extractType(Type $type): mixed
{
throw new \RuntimeException("Should never be called at runtime");
}
/**
* @template T
* @param Type<T> $t
* @return ListType<T>
*/
function listType(Type $t): ListType
{
return new ListType($t);
}
function intType(): IntType
{
return new IntType();
}
$listType = listType(intType());
$list = extractType($listType);
',
'assertions' => [
'$listType===' => 'ListType<int>',
'$list' => 'list<int>',
],
'ignored_issues' => [],
'php_version' => '8.2',
],
'validTemplatedType' => [
'code' => '<?php
namespace FooFoo;
Expand Down

0 comments on commit 25b07fb

Please sign in to comment.