Skip to content

Commit ee77709

Browse files
committed
more precise
1 parent 93ce29d commit ee77709

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

src/Type/Constant/ConstantArrayType.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
use PHPStan\Type\Generic\TemplateTypeMap;
3636
use PHPStan\Type\Generic\TemplateTypeVariance;
3737
use PHPStan\Type\IntegerRangeType;
38+
use PHPStan\Type\IntegerType;
3839
use PHPStan\Type\IntersectionType;
3940
use PHPStan\Type\IsSuperTypeOfResult;
4041
use PHPStan\Type\MixedType;
@@ -1378,8 +1379,8 @@ public function getKeysArrayFiltered(Type $filterValueType, bool $strict): Type
13781379

13791380
return TypeCombinator::intersect(
13801381
new ArrayType(
1381-
$keysArray->getIterableKeyType()->generalize(GeneralizePrecision::lessSpecific()),
1382-
$keysArray->getIterableValueType()->generalize(GeneralizePrecision::lessSpecific()),
1382+
new IntegerType(),
1383+
$keysArray->getIterableValueType(),
13831384
),
13841385
new AccessoryArrayListType(),
13851386
);

tests/PHPStan/Analyser/nsrt/bug-11928.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ function doFoo()
99
$a = [2 => 1, 3 => 2, 4 => 1];
1010

1111
$keys = array_keys($a, 1); // returns [2, 4]
12-
assertType('list<int>', $keys);
12+
assertType('list<2|3|4>', $keys);
1313

1414
$keys = array_keys($a); // returns [2, 3, 4]
1515
assertType('array{2, 3, 4}', $keys);
@@ -18,7 +18,7 @@ function doFoo()
1818
function doFooStrings() {
1919
$a = [2 => 'hi', 3 => '123', 'xy' => 5];
2020
$keys = array_keys($a, 1);
21-
assertType('list<int|string>', $keys);
21+
assertType("list<2|3|'xy'>", $keys);
2222

2323
$keys = array_keys($a);
2424
assertType("array{2, 3, 'xy'}", $keys);

0 commit comments

Comments
 (0)