mirror of
https://github.com/danog/psalm.git
synced 2024-11-29 20:28:59 +01:00
Allow setting property on templated type
This commit is contained in:
parent
6ec5763847
commit
f335560b69
@ -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;
|
||||
}
|
||||
|
@ -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;
|
||||
}'
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user