Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/PhpDoc/TypeNodeResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,7 @@ private function resolveIdentifierTypeNode(IdentifierTypeNode $typeNode, NameSco
return new IntersectionType([new ObjectWithoutClassType(), new CallableType()]);

case 'never':
case 'noreturn':
$type = $this->tryResolvePseudoTypeClassType($typeNode, $nameScope);

if ($type !== null) {
Expand All @@ -340,7 +341,6 @@ private function resolveIdentifierTypeNode(IdentifierTypeNode $typeNode, NameSco
case 'never-return':
case 'never-returns':
case 'no-return':
case 'noreturn':
return new NeverType(true);

case 'list':
Expand Down
1 change: 1 addition & 0 deletions tests/PHPStan/Analyser/NodeScopeResolverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1114,6 +1114,7 @@ public function dataFileAsserts(): iterable
yield from $this->gatherAssertTypes(__DIR__ . '/data/callable-string.php');

yield from $this->gatherAssertTypes(__DIR__ . '/data/bug-8225.php');
yield from $this->gatherAssertTypes(__DIR__ . '/data/bug-8242.php');
}

/**
Expand Down
60 changes: 60 additions & 0 deletions tests/PHPStan/Analyser/data/bug-8242.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<?php

namespace {
/**
* @return NoReturn
*/
function f1() {
throw new \LogicException();
}

/**
* @return \NoReturn
*/
function f2() {
return new NoReturn;
}

\PHPStan\Testing\assertType('*NEVER*', f1());
\PHPStan\Testing\assertType('NoReturn', f2());
}

namespace NoReturnDefined {
class NoReturn {}

/**
* @return NoReturn
*/
function f1() {
return new NoReturn;
}

/**
* @return \NoReturn
*/
function f2() {
return new \NoReturn;
}

\PHPStan\Testing\assertType('NoReturnDefined\\NoReturn', f1());
\PHPStan\Testing\assertType('NoReturn', f2());
}

namespace NoReturnUndefined {
/**
* @return NoReturn
*/
function f1() {
throw new \LogicException();
}

/**
* @return NoReturn
*/
function f2() {
throw new \LogicException();
}

\PHPStan\Testing\assertType('*NEVER*', f1());
\PHPStan\Testing\assertType('*NEVER*', f2());
}