Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit a4c6efc

Browse files
Fix OversizedArrayType::isSubTypeOf()
1 parent a80fd40 commit a4c6efc

File tree

3 files changed

+100
-4
lines changed

3 files changed

+100
-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+
}

‎tests/PHPStan/Type/TypeCombinatorTest.php‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5331,6 +5331,12 @@ public static function dataRemove(): array
53315331
ObjectShapeType::class,
53325332
'object{foo?: int}',
53335333
],
5334+
[
5335+
new IntersectionType([new ArrayType(new StringType(), new StringType()), new OversizedArrayType()]),
5336+
new ConstantArrayType([], []),
5337+
IntersectionType::class,
5338+
'non-empty-array<string, string>&oversized-array',
5339+
],
53345340
];
53355341
}
53365342

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /