-
-
Notifications
You must be signed in to change notification settings - Fork 933
Closed
Labels
Milestone
Description
Bug report
Missing key not reported after generic function, but reported for directly defined variable.
See it in playground:
https://phpstan.org/r/bf679482-96aa-49b2-8ac9-6f77a3a24fb1
Code snippet that reproduces the problem
<?php
declare(strict_types = 1);
/**
* @template T of int|string
*
* @param array<T,mixed> $arr
*
* @return array<T,string>
*/
function strings(array $arr): array
{
// @phpstan-ignore-next-line
return $arr;
}
$x = ['a' => 1];
$y = strings($x);
var_dump($x['b']);
var_dump($y['b']);
Expected output
22 | Offset 'b' does not exist on array{a: 1}.
23 | Offset 'b' does not exist on array{a: string}.
Did PHPStan help you today? Did it make you happy in any way?
Yes, great tool.