diff --git a/src/Analyser/MutatingScope.php b/src/Analyser/MutatingScope.php index b81f89088c..f4dfa47e6e 100644 --- a/src/Analyser/MutatingScope.php +++ b/src/Analyser/MutatingScope.php @@ -3684,13 +3684,15 @@ public function addTypeToExpression(Expr $expr, Type $type): self public function removeTypeFromExpression(Expr $expr, Type $typeToRemove): self { + if ($typeToRemove instanceof NeverType) { + return $this; + } + $exprType = $this->getType($expr); - if ( - $exprType instanceof NeverType || - $typeToRemove instanceof NeverType - ) { + if ($exprType instanceof NeverType) { return $this; } + return $this->specifyExpressionType( $expr, TypeCombinator::remove($exprType, $typeToRemove),