Skip to content

Commit 7870d2d

Browse files
committed
Regression test
Closes phpstan/phpstan#13135
1 parent e7da4dc commit 7870d2d

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

tests/PHPStan/Rules/Arrays/InvalidKeyInArrayDimFetchRuleTest.php

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class InvalidKeyInArrayDimFetchRuleTest extends RuleTestCase
1515

1616
protected function getRule(): Rule
1717
{
18-
$ruleLevelHelper = new RuleLevelHelper(self::createReflectionProvider(), true, false, true, false, false, false, true);
18+
$ruleLevelHelper = new RuleLevelHelper(self::createReflectionProvider(), true, false, true, true, true, false, true);
1919
return new InvalidKeyInArrayDimFetchRule($ruleLevelHelper, true);
2020
}
2121

@@ -38,6 +38,10 @@ public function testInvalidKey(): void
3838
'Invalid array key type DateTimeImmutable.',
3939
31,
4040
],
41+
[
42+
'Possibly invalid array key type mixed.',
43+
41,
44+
],
4145
[
4246
'Invalid array key type DateTimeImmutable.',
4347
45,
@@ -92,4 +96,14 @@ public function testBug6315(): void
9296
]);
9397
}
9498

99+
public function testBug13135(): void
100+
{
101+
$this->analyse([__DIR__ . '/data/bug-13135.php'], [
102+
[
103+
'Possibly invalid array key type Tk of mixed.',
104+
15,
105+
],
106+
]);
107+
}
108+
95109
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
namespace Bug13135;
4+
5+
/**
6+
* @template Tk
7+
* @template Tv
8+
*
9+
* @param iterable<Tk, Tv> $iterable
10+
*/
11+
function my_to_array(iterable $iterable): void
12+
{
13+
$result = [];
14+
foreach ($iterable as $k => $v) {
15+
$result[$k] = $v;
16+
}
17+
18+
var_dump($result);
19+
}

0 commit comments

Comments
 (0)