Skip to content

Commit 9bde094

Browse files
staabmondrejmirtes
authored andcommitted
Fix array_key_exists narrows $key too much
1 parent 056c434 commit 9bde094

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

src/Type/Php/ArrayKeyExistsFunctionTypeSpecifyingExtension.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public function specifyTypes(
5858
}
5959
$key = $node->getArgs()[0]->value;
6060
$array = $node->getArgs()[1]->value;
61-
$keyType = $scope->getType($key);
61+
$keyType = $scope->getType($key)->toArrayKey();
6262
$arrayType = $scope->getType($array);
6363

6464
if (
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
3+
namespace Bug11724;
4+
5+
use function PHPStan\Testing\assertType;
6+
7+
function doFoo() {
8+
$f = 5.0;
9+
$a = [5 => 'hello'];
10+
assertType('true', array_key_exists($f, $a));
11+
if (array_key_exists($f, $a)) {
12+
assertType('5.0', $f);
13+
assertType("array{5: 'hello'}", $a);
14+
}
15+
}

0 commit comments

Comments
 (0)