Skip to content

Commit 7dcaca5

Browse files
committed
more precise
1 parent f07e037 commit 7dcaca5

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;
@@ -1274,8 +1275,8 @@ public function getKeysArrayFiltered(Type $filterValueType, bool $strict): Type
12741275

12751276
return TypeCombinator::intersect(
12761277
new ArrayType(
1277-
$keysArray->getIterableKeyType()->generalize(GeneralizePrecision::lessSpecific()),
1278-
$keysArray->getIterableValueType()->generalize(GeneralizePrecision::lessSpecific()),
1278+
new IntegerType(),
1279+
$keysArray->getIterableValueType(),
12791280
),
12801281
new AccessoryArrayListType(),
12811282
);

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)