Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No way to annotate array key template #2568

Closed
muglug opened this issue Nov 10, 2019 · 3 comments
Closed

No way to annotate array key template #2568

muglug opened this issue Nov 10, 2019 · 3 comments
Labels
Milestone

Comments

@muglug
Copy link
Contributor

muglug commented Nov 10, 2019

Bug report

/**
 * @template T as int|string
 *
 * @param array<T, mixed> $arr
 * @return array<int, T>
 */
function my_array_keys($arr) {
	return array_keys($arr);
}

$a = my_array_keys(["hello" => 5, "goodbye" => new \Exception()]);

https://phpstan.org/r/b92e2661-21cd-4182-b987-312171de77fd

Expected output

No issues

Actual

Function my_array_keys() should return array<int, T> but returns array<int, (int|string)>.

@ondrejmirtes
Copy link
Member

The weirdest thing here is tha @template T as int|string isn't reported as unsupported, which it should be: https://phpstan.org/r/c4869d53-2241-455f-a705-5ab447090799

@ondrejmirtes
Copy link
Member

@github-actions
Copy link

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 29, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants