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

False positive PhanImpossibleCondition in switch #3222

Closed
mokraemer opened this issue Sep 6, 2019 · 4 comments · Fixed by #3223
Closed

False positive PhanImpossibleCondition in switch #3222

mokraemer opened this issue Sep 6, 2019 · 4 comments · Fixed by #3223
Labels
dead code detection Affects --dead-code-detection enhancement This improves the quality of Phan's analysis of a codebase

Comments

@mokraemer
Copy link

mokraemer commented Sep 6, 2019

Unused variable is emitted if a variable is assigned a value inside a switch/case without break:

class x{

	public static function f(int $x, $y): void{
		switch($x){
			case 1:
				$y = 2; //emits PhanUnusedVariable Unused definition of variable $y
//no break;
			case 2:
				echo $x . $y;
		}
	}

}
@mokraemer
Copy link
Author

sorry, I don't understand why the code is formated this way in this editor; attaching php files is not supported either. Hope you can read it anyway.

@mokraemer
Copy link
Author

mokraemer commented Sep 6, 2019

btw you can combine it with

$y=0;
switch($x){
  case 1:
    $y=2;
//no break;
  case 2:
    echo ($y?:'-'); // emits PhanImpossibleCondition Impossible attempt to cast $y of type 0 to truthy

}

@TysonAndre
Copy link
Member

The PhanImpossibleCondition is a new issue, the other issue is a duplicate of #1811

For future reference, use triple backticks, like so:

```php
php snippet/source code
```

@TysonAndre TysonAndre changed the title PhanUnusedVariable emitted if switch/case does not break False positive PhanImpossibleCondition in switch Sep 6, 2019
@TysonAndre TysonAndre added dead code detection Affects --dead-code-detection enhancement This improves the quality of Phan's analysis of a codebase labels Sep 6, 2019
@mokraemer
Copy link
Author

thx, used the button from this editor....

TysonAndre added a commit to TysonAndre/phan that referenced this issue Sep 6, 2019
TysonAndre added a commit to TysonAndre/phan that referenced this issue Sep 6, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dead code detection Affects --dead-code-detection enhancement This improves the quality of Phan's analysis of a codebase
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants