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

match() with isset is incorrectly warning about remaining value to use in branch #7095

Closed
tpetry opened this issue Apr 22, 2022 · 4 comments
Closed

Comments

@tpetry
Copy link

tpetry commented Apr 22, 2022

PHPStan is checking whether all possible outcomes of a match expression are used. But for isset it's reporting an error despite true and false are used.

Code snippet that reproduces the problem

/// PHPStan: Match expression does not handle remaining value: bool
match (isset($foo)) {
    true => 'a',
    false => 'b',
};

https://phpstan.org/r/4d740289-69d9-4071-825f-014bd4bdfecc

Expected output

The code is correct, as it has a branch for the true and false value.

@rajyan
Copy link
Contributor

rajyan commented Apr 22, 2022

This one #6910
and a comments in this PR is related.
It’s a type specifying problem.

@rajyan
Copy link
Contributor

rajyan commented Apr 22, 2022

I was on fixing this, but dropped priority because I think ternary operator can be better in these cases.

@ondrejmirtes
Copy link
Member

Fixed: phpstan/phpstan-src@3c7d9c8

Technically these issues will be true for all expression types handled above this if statement in MutatingScope::resolveType():

		$exprString = $this->getNodeKey($node);
		if (isset($this->moreSpecificTypes[$exprString]) && $this->moreSpecificTypes[$exprString]->getCertainty()->yes()) {
			return $this->moreSpecificTypes[$exprString]->getType();
		}

But for performance reasons we should move the handling only of those expressions that impact real-world scenarios.

@github-actions
Copy link

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 26, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants