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

array_merge should preserve the type #5864

Closed
b1rdex opened this issue Nov 1, 2021 · 3 comments
Closed

array_merge should preserve the type #5864

b1rdex opened this issue Nov 1, 2021 · 3 comments

Comments

@b1rdex
Copy link
Contributor

b1rdex commented Nov 1, 2021

Feature request

<?php declare(strict_types = 1);
use function PHPStan\dumpType;

/**
 * @param array{foo: string, bar: int} $bar
 */
function foo(array $bar): void {
	dumpType($bar + []); // nice
	dumpType($bar + ['zzz' => 1]); // very well!
	
	// all the examples below are faulty
	dumpType(array_merge($bar));
	dumpType(array_merge($bar, []));
	dumpType(array_merge($bar, ['zzz' => 1]));
}

https://phpstan.org/r/bb21ada0-44aa-4592-bec8-57fd8f958be9

Array concatenation works well, but array_merge drops the known type.
Would be really nice to preserve known types there too.

Did PHPStan help you today? Did it make you happy in any way?

Warm welcome v1!

@staabm
Copy link
Contributor

staabm commented Nov 1, 2021

duplicate of #5846 which shoule be fixed by phpstan/phpstan-src#696 ?

@b1rdex
Copy link
Contributor Author

b1rdex commented Nov 1, 2021

Nice, thank you!

@b1rdex b1rdex closed this as completed Nov 1, 2021
@github-actions
Copy link

github-actions bot commented Dec 3, 2021

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 Dec 3, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants