Skip to content

Commit 13b6747

Browse files
A list should only accept lists
1 parent cb8f910 commit 13b6747

File tree

4 files changed

+33
-1
lines changed

4 files changed

+33
-1
lines changed

src/Type/Constant/ConstantArrayType.php

+4
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,10 @@ public function acceptsWithReason(Type $type, bool $strictTypes): AcceptsResult
303303
return AcceptsResult::createFromBoolean(count($type->keyTypes) === 0);
304304
}
305305

306+
if ($this->isList()->yes() && $type->isList()->no()) {
307+
return AcceptsResult::createNo();
308+
}
309+
306310
$result = AcceptsResult::createYes();
307311
foreach ($this->keyTypes as $i => $keyType) {
308312
$valueType = $this->valueTypes[$i];

tests/PHPStan/Rules/Generators/YieldFromTypeRuleTest.php

-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ public function testRule(): void
3939
[
4040
'Generator expects value type array{DateTime, DateTime, stdClass, DateTimeImmutable}, array{0: DateTime, 1: DateTime, 2: stdClass, 4: DateTimeImmutable} given.',
4141
74,
42-
'Array does not have offset 3.',
4342
],
4443
[
4544
'Result of yield from (void) is used.',

tests/PHPStan/Rules/Methods/CallStaticMethodsRuleTest.php

+11
Original file line numberDiff line numberDiff line change
@@ -841,4 +841,15 @@ public function testClosureBind(): void
841841
]);
842842
}
843843

844+
public function testBug11600(): void
845+
{
846+
$this->checkThisOnly = false;
847+
$this->analyse([__DIR__ . '/data/bug-11600.php'], [
848+
[
849+
'Parameter #1 $array of static method Bug10600\HelloWorld::sayHello() expects array{1, 2}, array{1: 2, 0: 1} given.',
850+
18,
851+
],
852+
]);
853+
}
854+
844855
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
namespace Bug10600;
4+
5+
class HelloWorld
6+
{
7+
/** @param array{1, 2} $array */
8+
public static function sayHello(array $array): void
9+
{
10+
array_values($array)[0];
11+
}
12+
}
13+
14+
$a = [0 => 1, 1 => 2];
15+
$b = [1 => 2, 0 => 1];
16+
17+
HelloWorld::sayHello($a);
18+
HelloWorld::sayHello($b);

0 commit comments

Comments
 (0)