Skip to content

Commit 45b4a85

Browse files
committed
Regression test
Closes phpstan/phpstan#7173
1 parent 5a1c318 commit 45b4a85

File tree

4 files changed

+45
-0
lines changed

4 files changed

+45
-0
lines changed

Diff for: tests/PHPStan/Rules/Comparison/StrictComparisonOfDifferentTypesRuleTest.php

+5
Original file line numberDiff line numberDiff line change
@@ -906,4 +906,9 @@ public function testBug10493(): void
906906
$this->analyse([__DIR__ . '/data/bug-10493.php'], []);
907907
}
908908

909+
public function testBug7173(): void
910+
{
911+
$this->analyse([__DIR__ . '/data/bug-7173.php'], []);
912+
}
913+
909914
}

Diff for: tests/PHPStan/Rules/Comparison/data/bug-7173.php

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
namespace Bug7173;
4+
5+
function (): void {
6+
$a1 = [
7+
'item2' => 0,
8+
'item1' => 0,
9+
];
10+
11+
call_user_func(function () use (&$a1) {
12+
$a1['item2'] = 3;
13+
$a1['item1'] = 1;
14+
});
15+
16+
if (['item2' => 3, 'item1' => 1] === $a1) {
17+
throw new \Exception();
18+
}
19+
};

Diff for: tests/PHPStan/Rules/PhpDoc/WrongVariableNameInVarTagRuleTest.php

+4
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,10 @@ public function testRule(): void
140140
'PHPDoc tag @var above a function has no effect.',
141141
313,
142142
],
143+
[
144+
"PHPDoc tag @var with type array<int, mixed> is not subtype of native type array{: 'empty', 1: '1'}.",
145+
324,
146+
],
143147
]);
144148
}
145149

Diff for: tests/PHPStan/Rules/PhpDoc/data/wrong-variable-name-var.php

+17
Original file line numberDiff line numberDiff line change
@@ -314,3 +314,20 @@ function doFoo(): void
314314
{
315315

316316
}
317+
318+
class VarTagAboveLiteralArray
319+
{
320+
321+
public function doFoo(): void
322+
{
323+
/** @var array<int, mixed> */
324+
$arr = ['' => 'empty', 1 => '1'];
325+
}
326+
327+
public function doFoo2(): void
328+
{
329+
/** @var array<int|string, mixed> */
330+
$arr = ['' => 'empty', 1 => '1'];
331+
}
332+
333+
}

0 commit comments

Comments
 (0)