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

Allow setting property on templated type

This commit is contained in:
Brown 2020-05-19 17:31:05 -04:00
parent 6ec5763847
commit f335560b69
2 changed files with 29 additions and 1 deletions

View File

@ -225,7 +225,20 @@ class PropertyAssignmentAnalyzer
$has_valid_assignment_type = false;
foreach ($lhs_type->getAtomicTypes() as $lhs_type_part) {
$lhs_atomic_types = $lhs_type->getAtomicTypes();
while ($lhs_atomic_types) {
$lhs_type_part = \array_pop($lhs_atomic_types);
if ($lhs_type_part instanceof Type\Atomic\TTemplateParam) {
$lhs_atomic_types = \array_merge(
$lhs_atomic_types,
$lhs_type_part->as->getAtomicTypes()
);
continue;
}
if ($lhs_type_part instanceof TNull) {
continue;
}

View File

@ -2699,6 +2699,21 @@ class ClassTemplateTest extends TestCase
$fn($o);
}'
],
'changePropertyTypeOfTemplate' => [
'<?php
class A {
public int $x = 0;
}
/**
* @template T as A
* @param T $obj
* @param-out T $obj
*/
function foo(A &$obj): void {
$obj->x = 1;
}'
],
];
}