Skip to content

Commit

Permalink
Use NonAcceptingNeverType in more places
Browse files Browse the repository at this point in the history
  • Loading branch information
ondrejmirtes committed Aug 31, 2023
1 parent d44ae55 commit 3e03e9d
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 9 deletions.
7 changes: 4 additions & 3 deletions src/Analyser/MutatingScope.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@
use PHPStan\Type\IntersectionType;
use PHPStan\Type\MixedType;
use PHPStan\Type\NeverType;
use PHPStan\Type\NonAcceptingNeverType;
use PHPStan\Type\NonexistentParentClassType;
use PHPStan\Type\NullType;
use PHPStan\Type\ObjectShapeType;
Expand Down Expand Up @@ -676,7 +677,7 @@ private function getNodeKey(Expr $node): string
private function resolveType(string $exprString, Expr $node): Type
{
if ($node instanceof Expr\Exit_ || $node instanceof Expr\Throw_) {
return new NeverType(true);
return new NonAcceptingNeverType();
}

if (!$node instanceof Variable && $this->hasExpressionType($node)->yes()) {
Expand Down Expand Up @@ -1281,13 +1282,13 @@ private function resolveType(string $exprString, Expr $node): Type

if (count($returnTypes) === 0) {
if (count($closureExecutionEnds) > 0 && !$hasNull) {
$returnType = new NeverType(true);
$returnType = new NonAcceptingNeverType();
} else {
$returnType = new VoidType();
}
} else {
if (count($closureExecutionEnds) > 0) {
$returnTypes[] = new NeverType(true);
$returnTypes[] = new NonAcceptingNeverType();
}
if ($hasNull) {
$returnTypes[] = new NullType();
Expand Down
10 changes: 5 additions & 5 deletions tests/PHPStan/Analyser/data/closure-return-type.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,12 +111,12 @@ public function doBaz(): void
$f = function() {
$this->returnNever();
};
assertType('*NEVER*', $f());
assertType('never', $f());

$f = function(): void {
$this->returnNever();
};
assertType('*NEVER*', $f());
assertType('never', $f());

$f = function() {
if (rand(0, 1)) {
Expand All @@ -134,7 +134,7 @@ public function doBaz(): void

$this->returnNever();
};
assertType('*NEVER*', $f([]));
assertType('never', $f([]));

$f = function(array $a) {
foreach ($a as $v) {
Expand All @@ -148,12 +148,12 @@ public function doBaz(): void
$this->returnNever();
}
};
assertType('*NEVER*', $f());
assertType('never', $f());

$f = function (): \stdClass {
throw new \Exception();
};
assertType('*NEVER*', $f());
assertType('never', $f());
}

}
2 changes: 1 addition & 1 deletion tests/PHPStan/Analyser/data/throw-expr.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public function doFoo(bool $b): void

public function doBar(): void
{
assertType('*NEVER*', throw new \Exception());
assertType('never', throw new \Exception());
}

}

0 comments on commit 3e03e9d

Please sign in to comment.