Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/workflows/e2e-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions e2e/bug-14305/phpstan.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
parameters:
level: 5
paths:
- test.php
15 changes: 15 additions & 0 deletions e2e/bug-14305/test.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

namespace Bug14305;

define('BUG14305_XDOC_GMETA_EMTY', 0);
define('BUG14305_XDOC_GMETA_NUPATH', 7);
define('BUG14305_XDOC_GMETAS', [
'empty' => 0,
'nupath' => 7,
]);

$row = ['id' => 0];

foreach ([BUG14305_XDOC_GMETA_EMTY, BUG14305_XDOC_GMETA_NUPATH] as $meta)
$row[array_search($meta, BUG14305_XDOC_GMETAS)] = '';
2 changes: 1 addition & 1 deletion phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -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

-
Expand Down
17 changes: 17 additions & 0 deletions src/Type/Constant/ConstantArrayTypeBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Comment on lines +295 to +297
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess we need to use toArrayKey, as it also fails with "1", see https://phpstan.org/r/037d4dd3-a079-4e52-a184-e5fb050c97a3

wdyt @VincentLanglet ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I processed this review but have nothing to report.

Copy link
Contributor

@staabm staabm Mar 17, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm the origin reproducer causes a exception here:

throw new ShouldNotHappenException();

I feel this fix is wonky

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I processed this review but have nothing to report.

Copy link
Contributor

@VincentLanglet VincentLanglet Mar 17, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Scalar types should be already casted because of

$scalarTypes = $offsetType->toArrayKey()->getConstantScalarTypes();

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I processed this review but have nothing to report.


$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();
Expand Down
Loading