Skip to content

Commit

Permalink
Fixed dead code detection with isset()
Browse files Browse the repository at this point in the history
  • Loading branch information
ondrejmirtes committed Mar 19, 2019
1 parent 066e606 commit b43cc2c
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/Analyser/Scope.php
Expand Up @@ -395,11 +395,12 @@ private function resolveType(Expr $node): Type
if ($var instanceof Expr\Variable && is_string($var->name)) {
$variableType = $this->resolveType($var);
$isNullSuperType = (new NullType())->isSuperTypeOf($variableType);
if ($this->hasVariableType($var->name)->no() || $isNullSuperType->yes()) {
$has = $this->hasVariableType($var->name);
if ($has->no() || $isNullSuperType->yes()) {
return new ConstantBooleanType(false);
}

if (!$isNullSuperType->no()) {
if ($has->maybe() || !$isNullSuperType->no()) {
$result = new BooleanType();
}
continue;
Expand Down
16 changes: 16 additions & 0 deletions tests/PHPStan/Rules/DeadCode/data/unreachable.php
Expand Up @@ -36,4 +36,20 @@ public function doLorem()
// this is why...
}

/**
* @param \stdClass[] $all
*/
public function doIpsum(array $all)
{
foreach ($all as $a) {

}

if (isset($a)) {
throw new \Exception();
}

var_dump($a);
}

}

0 comments on commit b43cc2c

Please sign in to comment.