Skip to content

Commit 5581928

Browse files
committed
Fixed issue with arrow function type inference and TooWideArrowFunctionReturnTypehintRule
1 parent 1d0d3ad commit 5581928

2 files changed

Lines changed: 12 additions & 1 deletion

File tree

src/Rules/TooWideTypehints/TooWideArrowFunctionReturnTypehintRule.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,11 @@ public function processNode(Node $node, Scope $scope): array
2929
return [];
3030
}
3131

32-
$expr = $node->getOriginalNode()->expr;
32+
$arrowFunction = $node->getOriginalNode();
33+
if ($arrowFunction->returnType === null) {
34+
return [];
35+
}
36+
$expr = $arrowFunction->expr;
3337
if ($expr instanceof Node\Expr\YieldFrom || $expr instanceof Node\Expr\Yield_) {
3438
return [];
3539
}

tests/PHPStan/Rules/TooWideTypehints/data/tooWideArrowFunctionReturnType.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,11 @@ public function doFoo(?string $nullableString)
1616
fn (): ?string => $nullableString;
1717
}
1818

19+
public function doBar()
20+
{
21+
/** @var string[][] $data */
22+
$data = doFoo();
23+
array_reduce($data, static fn (int $carry, array $item) => $carry + $item['total_count'], 0);
24+
}
25+
1926
}

0 commit comments

Comments
 (0)