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

4.15 array_count_values wrong return type? causes DocblockTypeContradiction #7114

Closed
kkmuffme opened this issue Dec 9, 2021 · 3 comments · Fixed by #7115
Closed

4.15 array_count_values wrong return type? causes DocblockTypeContradiction #7114

kkmuffme opened this issue Dec 9, 2021 · 3 comments · Fixed by #7115

Comments

@kkmuffme
Copy link
Contributor

kkmuffme commented Dec 9, 2021

https://psalm.dev/r/97c8ae1796

Not sure what the issue is, just that it was working correctly up until at least 4.13, probably 4.14 too

@psalm-github-bot
Copy link

I found these snippets:

https://psalm.dev/r/97c8ae1796
<?php

$tokenized = preg_split( '/(?=[A-Z])|[0-9]/', '^SQP8F5s%6a1#iAl1w3@', -1, PREG_SPLIT_NO_EMPTY );
$length_count = array_map( 'strlen', $tokenized );

$occurence_count = array_count_values( $length_count );
ksort( $occurence_count );

$longest_token = array_key_last( $occurence_count );

if ( $longest_token === 1 ) {
	echo "hello";
}
Psalm output (using commit ae765df):

ERROR: DocblockTypeContradiction - 11:6 - 1 does not contain null

ERROR: DocblockTypeContradiction - 11:6 - Docblock-defined type null for $longest_token is never int(1)

@orklah
Copy link
Collaborator

orklah commented Dec 9, 2021

This is caused by #7045.

I'm reading it again and the stub shouldn't return array<empty, empty> when the param is not a non-empty-array, it should return array<TKey, positive-int>

@weirdan if you have a moment, mind fixing this? Otherwise I'll do it tomorrow afternoon

@weirdan
Copy link
Collaborator

weirdan commented Dec 10, 2021

Indeed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants