Skip to content

Missing key not reported after generic function #8166

@iliubinskii

Description

@iliubinskii

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions