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

Strange type assertion behavior after loop #5742

Closed
danog opened this issue May 10, 2021 · 2 comments
Closed

Strange type assertion behavior after loop #5742

danog opened this issue May 10, 2021 · 2 comments

Comments

@danog
Copy link
Collaborator

danog commented May 10, 2021

For some reason, string variables looses type information after a specific assertion with a body inside of a loop: https://psalm.dev/r/bcd4e3783f

The same does not happen if the assignment is removed from the body of the if: https://psalm.dev/r/f356d26882

@psalm-github-bot
Copy link

psalm-github-bot bot commented May 10, 2021

I found these snippets:

https://psalm.dev/r/bcd4e3783f
<?php
/** @var non-empty-string $function_id */;
if (function_exists($function_id)) {
	foreach (['a'] as $_) {
		if ($function_id === 'test') {
			$test = true;
			continue;
		}
	}
}
/** @psalm-trace $function_id */;
Psalm output (using commit 859b4a2):

INFO: Trace - 11:33 - $function_id: string

INFO: UnusedVariable - 6:4 - $test is never referenced or the value is not used
https://psalm.dev/r/f356d26882
<?php
/** @var non-empty-string $function_id */;
if (function_exists($function_id)) {
	foreach (['a'] as $_) {
		if ($function_id === 'test') {
			continue;
		}
	}
}
/** @psalm-trace $function_id */;
Psalm output (using commit 859b4a2):

INFO: Trace - 10:33 - $function_id: non-empty-string

@muglug
Copy link
Collaborator

muglug commented May 10, 2021

Now fixed, seems like

@muglug muglug closed this as completed May 10, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants