psalm icon indicating copy to clipboard operation
psalm copied to clipboard

Variable set inside catch is not propagated

Open danog opened this issue 2 years ago • 1 comments

https://psalm.dev/r/1368e04405

danog avatar Sep 20 '22 10:09 danog

I found these snippets:

https://psalm.dev/r/1368e04405
<?php
$retry = false;
try {
	try {
	} catch (Throwable $e) {
		$retry = true;
		throw $e;
	}
} finally {
	/** @psalm-trace $retry */;
	if (!$retry) {
	}
}
Psalm output (using commit 028ac7f):

INFO: Trace - 10:28 - $retry: false

ERROR: RedundantCondition - 11:6 - Operand of type true is always truthy

ERROR: RedundantCondition - 11:7 - Type false for $retry is always falsy

INFO: UnusedVariable - 6:3 - $retry is never referenced or the value is not used

psalm-github-bot[bot] avatar Sep 20 '22 10:09 psalm-github-bot[bot]