diff --git a/.github/workflows/e2e-tests.yml b/.github/workflows/e2e-tests.yml index c9357fa047..51891fb45c 100644 --- a/.github/workflows/e2e-tests.yml +++ b/.github/workflows/e2e-tests.yml @@ -308,6 +308,9 @@ jobs: cd e2e/discussion-11362 composer install ../../bin/phpstan + - script: | + cd e2e/bug-11819 + ../../bin/phpstan steps: - name: "Checkout" diff --git a/e2e/bug-11819/phpstan.neon b/e2e/bug-11819/phpstan.neon new file mode 100644 index 0000000000..5fbd64483a --- /dev/null +++ b/e2e/bug-11819/phpstan.neon @@ -0,0 +1,4 @@ +parameters: + level: 5 + paths: + - test.php diff --git a/e2e/bug-11819/test.php b/e2e/bug-11819/test.php new file mode 100644 index 0000000000..267e1647ad --- /dev/null +++ b/e2e/bug-11819/test.php @@ -0,0 +1,11 @@ +sanitizeConstantArrayKeyTypes($keyTypes); if ($keyTypes !== null) { - return new ConstantArrayType( - $keyTypes, - $valueTypes, - $keysParamType->getNextAutoIndexes(), - ); + $builder = ConstantArrayTypeBuilder::createEmpty(); + foreach ($keyTypes as $i => $keyType) { + $valueType = $valueTypes[$i]; + $builder->setOffsetValueType($keyType, $valueType); + } + + return $builder->getArray(); } } diff --git a/tests/PHPStan/Analyser/nsrt/array-combine-php8.php b/tests/PHPStan/Analyser/nsrt/array-combine-php8.php index 073fb23770..1e02759b5e 100644 --- a/tests/PHPStan/Analyser/nsrt/array-combine-php8.php +++ b/tests/PHPStan/Analyser/nsrt/array-combine-php8.php @@ -83,3 +83,11 @@ function withDifferentNumberOfElements(): void { assertType('*NEVER*', array_combine(['foo'], ['bar', 'baz'])); } + +function bug11819(): void +{ + $keys = [1, 2, 3]; + $types = array_combine($keys, array_fill(0, \count($keys), false)); + $types[] = 'foo'; + assertType('array{1: false, 2: false, 3: false, 4: \'foo\'}', $types); +}