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

Loop: uppercase literal strings inferred as non-empty-lowercase-string when combined with numeric-strings #9782

Closed
kkmuffme opened this issue May 13, 2023 · 1 comment · Fixed by #10722

Comments

@kkmuffme
Copy link
Contributor

https://psalm.dev/r/5dda068487

When a string is concat with int/numeric-string, psalm discards any literal non-lowercase-strings and just assumes they're all lowercase.

When using "normal" (non-numeric) strings it works correctly though (as the lower example shows)

@psalm-github-bot
Copy link

I found these snippets:

https://psalm.dev/r/5dda068487
<?php

/**
 * @return int[]
 */
function getIntArray() {}

$final = array();
foreach ( getIntArray() as $id ) {
 	$final[] = 'TEXT';
    $final[] = 'some_' . $id;
}

/** @psalm-trace $final */;

/**
 * @return string[]
 */
function getStringArray() {}

$final = array();
foreach ( getStringArray() as $id ) {
 	$final[] = 'TEXT';
    $final[] = 'some_' . $id;
}

/** @psalm-trace $final */;
Psalm output (using commit 2039667):

ERROR: InvalidReturnType - 4:12 - No return statements were found for method getIntArray but return type 'array<array-key, int>' was expected

INFO: Trace - 14:27 - $final: list<non-empty-lowercase-string>

ERROR: InvalidReturnType - 17:12 - No return statements were found for method getStringArray but return type 'array<array-key, string>' was expected

INFO: Trace - 27:27 - $final: list<non-empty-string>

kkmuffme added a commit to kkmuffme/psalm that referenced this issue Feb 19, 2024
…rings

* Fix vimeo#9782 and related issues
* add explicit handling for non-falsy-string to not fallback non-falsy-string and 0 to string
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.

2 participants