1
0
mirror of https://github.com/danog/psalm.git synced 2025-01-22 05:41:20 +01:00

Fix #5229 - new SomeTemplatedClass should expand out params even if none passed

This commit is contained in:
Matt Brown 2021-02-25 21:20:05 -05:00
parent d4841993b2
commit 474ebf912e
2 changed files with 31 additions and 0 deletions

View File

@ -472,6 +472,25 @@ class NewAnalyzer extends \Psalm\Internal\Analyzer\Statements\Expression\CallAna
)) {
// fall through
}
} elseif ($storage->template_types) {
$result_atomic_type = new Type\Atomic\TGenericObject(
$fq_class_name,
array_values(
array_map(
function($map) {
return clone reset($map);
},
$storage->template_types
)
)
);
$result_atomic_type->was_static = $from_static;
$statements_analyzer->node_data->setType(
$stmt,
new Type\Union([$result_atomic_type])
);
}
if ($storage->external_mutation_free) {

View File

@ -3343,6 +3343,18 @@ class ClassTemplateTest extends TestCase
}
}'
],
'newWithoutInferredTemplate' => [
'<?php
/**
* @psalm-template T2 of object
*/
final class Foo {}
$f = new Foo();',
[
'$f' => 'Foo<object>'
]
],
];
}