Skip to content

Analyzer should remember assertions done on a variable when using it inside a closure #4522

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

Closed
ondrejmirtes opened this issue Nov 9, 2020 · 1 comment
Labels

Comments

@ondrejmirtes
Copy link

https://psalm.dev/r/0541b5b720 - expected that $a can be just Identifier.

@psalm-github-bot
Copy link

I found these snippets:

https://psalm.dev/r/0541b5b720
<?php

namespace SpecifiedTypesClosureUse;

use PhpParser\Node\Expr\MethodCall;
use PhpParser\Node\Identifier;
use function PHPStan\Analyser\assertType;

class Foo
{

	public function doFoo(MethodCall $call): void
	{
		if ($call->name instanceof Identifier) {
			function () use ($call): void {
                /** @psalm-trace $a */
				$a = $call->name;
			};
		}
	}

}
Psalm output (using commit e97a9c8):

INFO: Trace - 17:5 - $a: PhpParser\Node\Expr|PhpParser\Node\Identifier

INFO: UnusedVariable - 17:5 - Variable $a is never referenced

@muglug muglug added the bug label Nov 9, 2020
@muglug muglug closed this as completed in 32d526b Nov 9, 2020
danog pushed a commit to danog/psalm that referenced this issue Jan 29, 2021

Verified

This commit was signed with the committer’s verified signature. The key has expired.
danog Daniil Gentili
Fixes vimeo#4522
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants