Skip to content

Commit 3f529a7

Browse files
committed
Intersection of array&hasOffset is accepted by non-empty-array
1 parent 94e85e8 commit 3f529a7

4 files changed

Lines changed: 24 additions & 5 deletions

File tree

src/Type/Accessory/NonEmptyArrayType.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,6 @@ public function getConstantStrings(): array
7676

7777
public function accepts(Type $type, bool $strictTypes): AcceptsResult
7878
{
79-
if ($type instanceof CompoundType) {
80-
return $type->isAcceptedBy($this, $strictTypes);
81-
}
82-
8379
$isArray = $type->isArray();
8480
$isIterableAtLeastOnce = $type->isIterableAtLeastOnce();
8581

src/Type/UnionType.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1235,7 +1235,7 @@ private function notBenevolentUnionResults(callable $getResult): TrinaryLogic
12351235
protected function unionTypes(callable $getType): Type
12361236
{
12371237
$newTypes = [];
1238-
foreach($this->types as $type) {
1238+
foreach ($this->types as $type) {
12391239
$newTypes[] = $getType($type);
12401240
}
12411241

tests/PHPStan/Rules/Functions/ClosureReturnTypeRuleTest.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,4 +133,10 @@ public function testBugFunctionMethodConstants(): void
133133
$this->analyse([__DIR__ . '/data/bug-anonymous-function-method-constant.php'], []);
134134
}
135135

136+
public function testBug13964(): void
137+
{
138+
$this->analyse([__DIR__ . '/data/bug-13964.php'], []);
139+
}
140+
141+
136142
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
namespace Bug13964;
4+
5+
/** @var array<string, array<mixed>> $state */
6+
$state = (fn()=>[])();
7+
8+
$state = array_map(function (array $item): array {
9+
if (array_key_exists('type', $item) && array_key_exists('data', $item)) {
10+
return $item;
11+
}
12+
13+
return [
14+
'type' => 'hello',
15+
'data' => [],
16+
];
17+
}, $state);

0 commit comments

Comments
 (0)