Bug report
This is similar to #1847, but we're still getting the error with phpstan 0.11.19 and 0.12.5.
Even though the array key type is known, in some situations it is not used to infer the type of array_keys().
Code snippet that reproduces the problem
/**
* @param array<string, true> $knownAliases
*/
function getSQLForJoins(string $fromAlias, array &$knownAliases) : string
{
...
throw NonUniqueAlias::new($join['joinAlias'], array_keys($knownAliases));
Here the type of array_keys($knownAliases) is inferred as array<int, int|string> instead of array<int, string>.
Sandbox: https://phpstan.org/r/98b7db20-f773-49d9-86d7-014f5d209483
Travis: https://travis-ci.org/doctrine/dbal/jobs/638201455
If you remove lines 45-48 (after the culprit), it suddenly works:
https://phpstan.org/r/586a6826-b4f7-4ea0-8c62-f3fa8a643a1a
Expected output
Actual output
------ -----------------------------------------------------------------------------------------------------------------------------------------------------------
Line lib/Doctrine/DBAL/Query/QueryBuilder.php
------ -----------------------------------------------------------------------------------------------------------------------------------------------------------
1319 Parameter #2 $registeredAliases of static method Doctrine\DBAL\Query\Exception\NonUniqueAlias::new() expects array<string>, array<int, int|string> given.
------ -----------------------------------------------------------------------------------------------------------------------------------------------------------
Bug report
This is similar to #1847, but we're still getting the error with phpstan
0.11.19and0.12.5.Even though the array key type is known, in some situations it is not used to infer the type of
array_keys().Code snippet that reproduces the problem
Here the type of
array_keys($knownAliases)is inferred asarray<int, int|string>instead ofarray<int, string>.Sandbox: https://phpstan.org/r/98b7db20-f773-49d9-86d7-014f5d209483
Travis: https://travis-ci.org/doctrine/dbal/jobs/638201455
If you remove lines 45-48 (after the culprit), it suddenly works:
https://phpstan.org/r/586a6826-b4f7-4ea0-8c62-f3fa8a643a1a
Expected output
Actual output