Skip to content

Commit 7458a53

Browse files
committed
fix
1 parent 63ab317 commit 7458a53

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

src/Type/Php/ArrayKeyExistsFunctionTypeSpecifyingExtension.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ public function specifyTypes(
122122
&& !$arrayType->isArray()->yes()
123123
) {
124124
$type = new ArrayType(new MixedType(), new MixedType());
125+
$type = $type->unsetOffset($keyType);
125126
$context = $context->negate();
126127
} else {
127128
$type = new HasOffsetType($keyType);

tests/PHPStan/Analyser/nsrt/bug-13301-php8.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ function doFoo($mixed) {
99
assertType("non-empty-array&hasOffset('a')", $mixed);
1010
echo "has-a";
1111
} else {
12-
assertType('array', $mixed); // could be array~hasOffset('a') after arrays got subtractable
12+
assertType("array<mixed~'a', mixed>", $mixed);
1313
echo "NO-a";
1414
}
1515
assertType('array', $mixed);
@@ -19,7 +19,7 @@ function doFooTrue($mixed) {
1919
if (array_key_exists('a', $mixed) === true) {
2020
assertType("non-empty-array&hasOffset('a')", $mixed);
2121
} else {
22-
assertType('array', $mixed); // could be array~hasOffset('a') after arrays got subtractable
22+
assertType("array<mixed~'a', mixed>", $mixed);
2323
}
2424
assertType('array', $mixed);
2525
}
@@ -28,14 +28,14 @@ function doFooTruethy($mixed) {
2828
if (array_key_exists('a', $mixed) == true) {
2929
assertType("non-empty-array&hasOffset('a')", $mixed);
3030
} else {
31-
assertType('array', $mixed); // could be array~hasOffset('a') after arrays got subtractable
31+
assertType("array<mixed~'a', mixed>", $mixed);
3232
}
3333
assertType('array', $mixed);
3434
}
3535

3636
function doFooFalsey($mixed) {
3737
if (array_key_exists('a', $mixed) == 0) {
38-
assertType("array", $mixed);
38+
assertType("array<mixed~'a', mixed>", $mixed);
3939
} else {
4040
assertType("non-empty-array&hasOffset('a')", $mixed);
4141
}

0 commit comments

Comments
 (0)