Skip to content

Commit 74b397d

Browse files
Fix oversizeArrayType->isSubTypeOf
1 parent a5aa2ce commit 74b397d

File tree

2 files changed

+94
-4
lines changed

2 files changed

+94
-4
lines changed

src/Type/IntersectionType.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -247,10 +247,12 @@ public function isSubTypeOf(Type $otherType): IsSuperTypeOfResult
247247
}
248248

249249
$result = IsSuperTypeOfResult::maxMin(...array_map(static fn (Type $innerType) => $otherType->isSuperTypeOf($innerType), $this->types));
250-
if ($this->isOversizedArray()->yes()) {
251-
if (!$result->no()) {
252-
return IsSuperTypeOfResult::createYes();
253-
}
250+
if (
251+
!$result->no()
252+
&& $this->isOversizedArray()->yes()
253+
&& !$otherType->isIterableAtLeastOnce()->no()
254+
) {
255+
return IsSuperTypeOfResult::createYes();
254256
}
255257

256258
return $result;
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
<?php declare(strict_types = 1);
2+
3+
namespace Bug13509;
4+
5+
use function PHPStan\Testing\assertType;
6+
7+
/** @return ?array<string, mixed> */
8+
function alert(): ?array
9+
{
10+
$alerts = [];
11+
12+
if (rand()) {
13+
$alerts[] = [
14+
'message' => "Foo",
15+
'details' => "bar",
16+
'duration' => rand() ?: null,
17+
'severity' => 100,
18+
];
19+
}
20+
21+
if (rand()) {
22+
$alerts[] = [
23+
'message' => 'Offline',
24+
'duration' => rand() ?: null,
25+
'severity' => 99,
26+
];
27+
}
28+
29+
if (rand()) {
30+
$alerts[] = [
31+
'message' => 'Running W/O Operator',
32+
'duration' => rand() ?: null,
33+
'severity' => 75,
34+
];
35+
}
36+
37+
if (rand()) {
38+
$alerts[] = [
39+
'message' => 'No Queue',
40+
'duration' => rand() ?: null,
41+
'severity' => 60,
42+
];
43+
}
44+
45+
if (rand()) {
46+
if (rand()) {
47+
$alerts[] = [
48+
'message' => 'Not Scheduled',
49+
'duration' => null,
50+
'severity' => 25,
51+
];
52+
}
53+
54+
if (rand()) {
55+
$alerts[] = [
56+
'message' => 'On Lunch',
57+
'duration' => rand() ?: null,
58+
'severity' => 24,
59+
];
60+
}
61+
62+
if (rand()) {
63+
$alerts[] = [
64+
'message' => 'On Break',
65+
'duration' => rand() ?: null,
66+
'severity' => 24,
67+
];
68+
}
69+
}
70+
71+
if (rand()) {
72+
$alerts[] = [
73+
'message' => 'Idle',
74+
'duration' => rand() ?: null,
75+
'severity' => 23,
76+
];
77+
}
78+
79+
if ($alerts === []) {
80+
return null;
81+
}
82+
83+
assertType('non-empty-list<non-empty-array<literal-string&lowercase-string&non-falsy-string, int|(literal-string&non-falsy-string)|null>&oversized-array>&oversized-array', $alerts);
84+
85+
usort($alerts, fn ($a, $b) => $b['severity'] <=> $a['severity']);
86+
87+
return $alerts[0];
88+
}

0 commit comments

Comments
 (0)