Skip to content
Open
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: 2 additions & 0 deletions src/Analyser/NodeScopeResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -907,6 +907,8 @@ public function processStmtNode(
return new InternalStatementResult($scope, $hasYield, true, [
new InternalStatementExitPoint($stmt, $scope),
], $overridingThrowPoints ?? $throwPoints, $impurePoints);
} elseif ($stmt instanceof Node\Stmt\Goto_) {
return new InternalStatementResult($scope, false, true, [], $overridingThrowPoints ?? [], []);
} elseif ($stmt instanceof Node\Stmt\Expression) {
if ($stmt->expr instanceof Expr\Throw_) {
$scope = $stmtScope;
Expand Down
7 changes: 7 additions & 0 deletions tests/PHPStan/Rules/Missing/MissingReturnRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -373,4 +373,11 @@ public function testBug12722(): void
$this->analyse([__DIR__ . '/data/bug-12722.php'], []);
}

#[RequiresPhp('>= 8.0')]
public function testBug9444(): void
{
$this->checkExplicitMixedMissingReturn = true;
$this->analyse([__DIR__ . '/data/bug-9444.php'], []);
}

}
53 changes: 53 additions & 0 deletions tests/PHPStan/Rules/Missing/data/bug-9444.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?php // lint >= 8.0

declare(strict_types = 1);

namespace Bug9444;

class HelloWorld
{

/** @throws \Exception */
public static function riskyOp(): string
{
return 'ok';
}

public function gotoRetry(): string
{
$i = 0;
beginning:
try {
return self::riskyOp();
} catch (\Throwable $e) {
if (++$i < 5) {
goto beginning;
} else {
throw $e;
}
}
}

public function gotoRetrySimple(): string
{
beginning:
try {
return self::riskyOp();
} catch (\Throwable $e) {
goto beginning;
}
}

public function gotoInCatch(): int
{
$result = 0;
beginning:
try {
$result = random_int(1, 100);
} catch (\Throwable $e) {
goto beginning;
}
return $result;
}

}
Loading