1
0
mirror of https://github.com/danog/psalm.git synced 2024-11-30 04:39:00 +01:00

Try to fix template replacement edge case

This commit is contained in:
klimick 2024-01-22 07:09:57 +03:00
parent b7a18bde46
commit c307bcbc76
2 changed files with 62 additions and 2 deletions

View File

@ -1254,7 +1254,6 @@ final class TemplateStandinTypeReplacer
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)) {
@ -1290,7 +1289,6 @@ final class TemplateStandinTypeReplacer
$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 => $_) {

View File

@ -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;