Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 41d3f1c

Browse files
rvanvelzenondrejmirtes
authored andcommitted
Fix closure return type for different same-code array_map argumnets in same scope
1 parent 71ced81 commit 41d3f1c

File tree

3 files changed

+64
-1
lines changed

3 files changed

+64
-1
lines changed

‎src/Analyser/MutatingScope.php‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -666,7 +666,17 @@ public function getType(Expr $node): Type
666666

667667
private function getNodeKey(Expr $node): string
668668
{
669-
return $this->exprPrinter->printExpr($node);
669+
$key = $this->exprPrinter->printExpr($node);
670+
671+
if (
672+
$node instanceof Node\FunctionLike
673+
&& $node->hasAttribute(ArrayMapArgVisitor::ATTRIBUTE_NAME)
674+
&& $node->hasAttribute('startFilePos')
675+
) {
676+
$key .= '/*' . $node->getAttribute('startFilePos') . '*/';
677+
}
678+
679+
return $key;
670680
}
671681

672682
private function resolveType(Expr $node): Type

‎tests/PHPStan/Rules/Functions/ArrowFunctionReturnTypeRuleTest.php‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use PHPStan\Rules\Rule;
77
use PHPStan\Rules\RuleLevelHelper;
88
use PHPStan\Testing\RuleTestCase;
9+
use const PHP_VERSION_ID;
910

1011
/**
1112
* @extends RuleTestCase<ArrowFunctionReturnTypeRule>
@@ -44,4 +45,13 @@ public function testBug3261(): void
4445
$this->analyse([__DIR__ . '/data/bug-3261.php'], []);
4546
}
4647

48+
public function testBug8179(): void
49+
{
50+
if (PHP_VERSION_ID < 80100) {
51+
$this->markTestSkipped('Test requires PHP 8.1.');
52+
}
53+
54+
$this->analyse([__DIR__ . '/data/bug-8179.php'], []);
55+
}
56+
4757
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?php // lint >= 8.1
2+
3+
namespace Bug8179;
4+
5+
enum Row
6+
{
7+
case I;
8+
case II;
9+
case III;
10+
}
11+
12+
enum Column
13+
{
14+
case A;
15+
case B;
16+
case C;
17+
}
18+
19+
function prepareMatrix(): array
20+
{
21+
$matrix = array_fill_keys(
22+
array_map(fn($v) => $v->name, Row::cases()),
23+
array_fill_keys(array_map(fn($v) => $v->name, Column::cases()), null)
24+
);
25+
26+
foreach ($matrix as $row => $columns) {
27+
foreach ($columns as $column => $value) {
28+
$matrix[$row][$column] = $row.$column;
29+
}
30+
}
31+
32+
return $matrix;
33+
}
34+
35+
function showMatrix(array $matrix): void
36+
{
37+
foreach ($matrix as $rows) {
38+
foreach ($rows as $cell) {
39+
echo $cell."\t";
40+
}
41+
echo PHP_EOL;
42+
}
43+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /