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
5 changes: 5 additions & 0 deletions src/Rules/Cast/UselessCastRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use PhpParser\Node;
use PhpParser\Node\Expr\Cast;
use PhpParser\Node\Expr\Cast\Void_;
use PHPStan\Analyser\Scope;
use PHPStan\Rules\Rule;
use PHPStan\Rules\RuleErrorBuilder;
Expand Down Expand Up @@ -38,6 +39,10 @@ public function getNodeType(): string

public function processNode(Node $node, Scope $scope): array
{
if ($node instanceof Void_) {
return [];
}

$castType = $scope->getType($node);
if ($castType instanceof ErrorType) {
return [];
Expand Down
6 changes: 6 additions & 0 deletions tests/Rules/Cast/UselessCastRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,4 +89,10 @@ public function testReportPhpDoc(): void
]);
}

public function testBug14565(): void
{
$this->treatPhpDocTypesAsCertain = true;
$this->analyse([__DIR__ . '/data/bug-14565.php'], []);
}

}
18 changes: 18 additions & 0 deletions tests/Rules/Cast/data/bug-14565.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php // lint >= 8.5

namespace Bug14565;

class Foo
{

#[\NoDiscard]
public function bar(): int
{
return 1;
}

}

function (Foo $foo): void {
(void) $foo->bar();
};
Loading