mirror of
https://github.com/danog/psalm.git
synced 2024-11-30 04:39:00 +01:00
Fix #1676 - don’t modify original param types with templated by-reference
This commit is contained in:
parent
62dacaf97b
commit
9fb96793cd
@ -1455,7 +1455,7 @@ class CallAnalyzer
|
||||
$generic_params = [];
|
||||
}
|
||||
|
||||
$original_by_ref_type = $by_ref_type;
|
||||
$original_by_ref_type = clone $by_ref_type;
|
||||
|
||||
$by_ref_type = clone $by_ref_type;
|
||||
|
||||
|
@ -2538,6 +2538,40 @@ class TemplateTest extends TestCase
|
||||
'$a' => 'C&I<C>'
|
||||
]
|
||||
],
|
||||
'dontModifyByRefTemplatedArray' => [
|
||||
'<?php
|
||||
class A {}
|
||||
class B {}
|
||||
|
||||
/**
|
||||
* @template T of object
|
||||
* @param class-string<T> $className
|
||||
* @param array<T> $map
|
||||
* @param-out array<T> $map
|
||||
* @param int $id
|
||||
* @return T
|
||||
*/
|
||||
function get(string $className, array &$map, int $id) {
|
||||
if(!array_key_exists($id, $map)) {
|
||||
$map[$id] = new $className();
|
||||
}
|
||||
return $map[$id];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<A> $mapA
|
||||
*/
|
||||
function getA(int $id, array $mapA): A {
|
||||
return get(A::class, $mapA, $id);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<B> $mapB
|
||||
*/
|
||||
function getB(int $id, array $mapB): B {
|
||||
return get(B::class, $mapB, $id);
|
||||
}'
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user