Skip to content

Commit f98a734

Browse files
Add test
1 parent 016d568 commit f98a734

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

src/Type/Php/ArrayCombineHelper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ private function sanitizeConstantArrayKeyTypes(array $types): ?array
116116
$sanitizedTypes = [];
117117

118118
foreach ($types as $type) {
119-
if ($type->isInteger()->no() && ! $type->toString() instanceof ErrorType) {
119+
if (!$type->isInteger()->yes() && ! $type->toString() instanceof ErrorType) {
120120
$type = $type->toString();
121121
}
122122

tests/PHPStan/Analyser/nsrt/array-combine-php8.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,3 +147,18 @@ function bug11819(): void
147147
$types[] = 'foo';
148148
assertType('array{1: false, 2: false, 3: false, 4: \'foo\'}', $types);
149149
}
150+
151+
function withMixed(mixed $mixed1, mixed $mixed2)
152+
{
153+
assertType('array', array_combine($mixed1, $mixed2));
154+
}
155+
156+
/**
157+
* @param 1|true $oneOrBool
158+
*/
159+
function withUnionAsKey(int|bool $oneOrBool)
160+
{
161+
$keys = [$oneOrBool];
162+
163+
assertType(" array{1: 'bar'}", array_combine($keys, ['bar']));
164+
}

0 commit comments

Comments
 (0)