Skip to content

Commit 000330b

Browse files
committed
Fix bug in array-shape subtraction
1 parent 708d938 commit 000330b

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

src/Type/Constant/ConstantArrayType.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,17 @@ public function isSuperTypeOf(Type $type): TrinaryLogic
367367
return $type->isIterableAtLeastOnce()->negate();
368368
}
369369

370+
if (
371+
$this->isList->yes()
372+
&& $type->isList->yes()
373+
&& count($this->keyTypes) !== count($type->keyTypes)
374+
) {
375+
if (count($type->optionalKeys) > 0) {
376+
return TrinaryLogic::createMaybe();
377+
}
378+
return TrinaryLogic::createNo();
379+
}
380+
370381
$results = [];
371382
foreach ($this->keyTypes as $i => $keyType) {
372383
$hasOffset = $type->hasOffsetValueType($keyType);
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
3+
namespace Bug11488;
4+
5+
use function PHPStan\Testing\assertType;
6+
7+
class Foo
8+
{
9+
/**
10+
* @param array{mixed}|array{mixed, string|null, mixed} $row
11+
*/
12+
protected function test(array $row): void
13+
{
14+
if (count($row) !== 1) {
15+
assertType('array{mixed, string|null, mixed}', $row);
16+
}
17+
18+
if (count($row) !== 2) {
19+
assertType('array{mixed, string|null, mixed}|array{mixed}', $row);
20+
}
21+
22+
if (count($row) !== 3) {
23+
assertType('array{mixed}', $row);
24+
}
25+
}
26+
}

0 commit comments

Comments
 (0)