diff --git a/.github/workflows/e2e-tests.yml b/.github/workflows/e2e-tests.yml index 167eeda27a..4237d3f41b 100644 --- a/.github/workflows/e2e-tests.yml +++ b/.github/workflows/e2e-tests.yml @@ -380,6 +380,9 @@ jobs: - script: | cd e2e/bug-11819 ../../bin/phpstan + - script: | + cd e2e/bug-14305 + ../../bin/phpstan - script: | cd e2e/composer-and-phpstan-version-config composer install --ignore-platform-reqs diff --git a/e2e/bug-14305/phpstan.neon b/e2e/bug-14305/phpstan.neon new file mode 100644 index 0000000000..5fbd64483a --- /dev/null +++ b/e2e/bug-14305/phpstan.neon @@ -0,0 +1,4 @@ +parameters: + level: 5 + paths: + - test.php diff --git a/e2e/bug-14305/test.php b/e2e/bug-14305/test.php new file mode 100644 index 0000000000..b7daf92cfe --- /dev/null +++ b/e2e/bug-14305/test.php @@ -0,0 +1,15 @@ + 0, + 'nupath' => 7, +]); + +$row = ['id' => 0]; + +foreach ([BUG14305_XDOC_GMETA_EMTY, BUG14305_XDOC_GMETA_NUPATH] as $meta) + $row[array_search($meta, BUG14305_XDOC_GMETAS)] = ''; diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 6c3ff7e153..78d6e328a5 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -966,7 +966,7 @@ parameters: - rawMessage: PHPDoc tag @var with type float|int is not subtype of native type int. identifier: varTag.nativeType - count: 2 + count: 3 path: src/Type/Constant/ConstantArrayTypeBuilder.php - diff --git a/src/Type/Constant/ConstantArrayTypeBuilder.php b/src/Type/Constant/ConstantArrayTypeBuilder.php index c901306f28..aab3b8ad44 100644 --- a/src/Type/Constant/ConstantArrayTypeBuilder.php +++ b/src/Type/Constant/ConstantArrayTypeBuilder.php @@ -291,6 +291,23 @@ public function setOffsetValueType(?Type $offsetType, Type $valueType, bool $opt $this->keyTypes[] = $scalarType; $this->valueTypes[] = $valueType; $this->optionalKeys[] = count($this->keyTypes) - 1; + + if (!($scalarType instanceof ConstantIntegerType)) { + continue; + } + + $max = max($this->nextAutoIndexes); + $offsetValue = $scalarType->getValue(); + if ($offsetValue < $max) { + continue; + } + + /** @var int|float $newAutoIndex */ + $newAutoIndex = $offsetValue + 1; + if (is_float($newAutoIndex)) { + $newAutoIndex = $max; + } + $this->nextAutoIndexes[] = $newAutoIndex; } $this->isList = TrinaryLogic::createNo();