Skip to content
Closed
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
1 change: 1 addition & 0 deletions src/Analyser/NodeScopeResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -3877,6 +3877,7 @@ function (MutatingScope $scope) use ($stmt, $expr, $nodeCallback, $context, $sto
$scope = $result->getScope();
$hasYield = $hasYield || $result->hasYield();
$throwPoints = array_merge($throwPoints, $result->getThrowPoints());
$throwPoints[] = InternalThrowPoint::createImplicit($scope, $expr);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this is the right way to fix this since

  • other catch won't be reported
  • Something like
public static function tryFromName2(): ?self
	{
		$name = 'EMOJI_HEART';
		try {
			return ReactionType::{$name};
		} catch (\Error) {
			return null;
		}
	}

won't be reported

$impurePoints = array_merge($impurePoints, $result->getImpurePoints());
$isAlwaysTerminating = $isAlwaysTerminating || $result->isAlwaysTerminating();
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -667,6 +667,11 @@ public function testBug9146(): void
]);
}

public function testBug13569(): void
{
$this->analyse([__DIR__ . '/data/bug-13569.php'], []);
}

public function testBug9146NonStrict(): void
{
$this->analyse([__DIR__ . '/data/bug-9146-non-strict.php'], [
Expand Down
19 changes: 19 additions & 0 deletions tests/PHPStan/Rules/Exceptions/data/bug-13569.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php // lint >= 8.1

declare(strict_types = 1);

namespace Bug13569;

enum ReactionType: string
{
case EMOJI_HEART = '❤️';

public static function tryFromName(string $name): ?self
{
try {
return ReactionType::{$name};
} catch (\Error) {
return null;
}
}
}
Loading