Skip to content

Commit a4b28bc

Browse files
committed
resolveType for (unset) cast
1 parent f81fc8a commit a4b28bc

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

src/Analyser/ExprHandler/CastHandler.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
use PHPStan\Analyser\NodeScopeResolver;
1414
use PHPStan\DependencyInjection\AutowiredService;
1515
use PHPStan\Reflection\InitializerExprTypeResolver;
16+
use PHPStan\Type\NullType;
1617
use PHPStan\Type\Type;
1718

1819
/**
@@ -54,6 +55,10 @@ public function processExpr(NodeScopeResolver $nodeScopeResolver, Stmt $stmt, Ex
5455
*/
5556
public function resolveType(MutatingScope $scope, Expr $expr): Type
5657
{
58+
if ($expr instanceof Cast\Unset_) {
59+
return new NullType();
60+
}
61+
5762
return $this->initializerExprTypeResolver->getCastType($expr, static fn (Expr $expr): Type => $scope->getType($expr));
5863
}
5964

src/Analyser/MutatingScope.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
use PhpParser\Node\Expr;
99
use PhpParser\Node\Expr\Array_;
1010
use PhpParser\Node\Expr\BinaryOp;
11-
use PhpParser\Node\Expr\Cast\Unset_;
1211
use PhpParser\Node\Expr\ConstFetch;
1312
use PhpParser\Node\Expr\FuncCall;
1413
use PhpParser\Node\Expr\Match_;
@@ -1071,10 +1070,6 @@ private function resolveType(string $exprString, Expr $node): Type
10711070
return $this->nativeTypesPromoted ? $node->getNativeExprType() : $node->getExprType();
10721071
}
10731072

1074-
if ($node instanceof Unset_) {
1075-
return new NullType();
1076-
}
1077-
10781073
if ($node instanceof MethodCall) {
10791074
$callType = $this->getMethodCallType($node);
10801075
if ($callType !== null) {

0 commit comments

Comments
 (0)