Skip to content

Commit 55717f6

Browse files
Fix phpstan/phpstan#14305: Internal error crash report (#5231)
Co-authored-by: Vincent Langlet <vincentlanglet@hotmail.fr>
1 parent abe090e commit 55717f6

File tree

5 files changed

+40
-1
lines changed

5 files changed

+40
-1
lines changed

.github/workflows/e2e-tests.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,9 @@ jobs:
380380
- script: |
381381
cd e2e/bug-11819
382382
../../bin/phpstan
383+
- script: |
384+
cd e2e/bug-14305
385+
../../bin/phpstan
383386
- script: |
384387
cd e2e/composer-and-phpstan-version-config
385388
composer install --ignore-platform-reqs

e2e/bug-14305/phpstan.neon

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
parameters:
2+
level: 5
3+
paths:
4+
- test.php

e2e/bug-14305/test.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
3+
namespace Bug14305;
4+
5+
define('BUG14305_XDOC_GMETA_EMTY', 0);
6+
define('BUG14305_XDOC_GMETA_NUPATH', 7);
7+
define('BUG14305_XDOC_GMETAS', [
8+
'empty' => 0,
9+
'nupath' => 7,
10+
]);
11+
12+
$row = ['id' => 0];
13+
14+
foreach ([BUG14305_XDOC_GMETA_EMTY, BUG14305_XDOC_GMETA_NUPATH] as $meta)
15+
$row[array_search($meta, BUG14305_XDOC_GMETAS)] = '';

phpstan-baseline.neon

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -966,7 +966,7 @@ parameters:
966966
-
967967
rawMessage: PHPDoc tag @var with type float|int is not subtype of native type int.
968968
identifier: varTag.nativeType
969-
count: 2
969+
count: 3
970970
path: src/Type/Constant/ConstantArrayTypeBuilder.php
971971

972972
-

src/Type/Constant/ConstantArrayTypeBuilder.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,23 @@ public function setOffsetValueType(?Type $offsetType, Type $valueType, bool $opt
291291
$this->keyTypes[] = $scalarType;
292292
$this->valueTypes[] = $valueType;
293293
$this->optionalKeys[] = count($this->keyTypes) - 1;
294+
295+
if (!($scalarType instanceof ConstantIntegerType)) {
296+
continue;
297+
}
298+
299+
$max = max($this->nextAutoIndexes);
300+
$offsetValue = $scalarType->getValue();
301+
if ($offsetValue < $max) {
302+
continue;
303+
}
304+
305+
/** @var int|float $newAutoIndex */
306+
$newAutoIndex = $offsetValue + 1;
307+
if (is_float($newAutoIndex)) {
308+
$newAutoIndex = $max;
309+
}
310+
$this->nextAutoIndexes[] = $newAutoIndex;
294311
}
295312

296313
$this->isList = TrinaryLogic::createNo();

0 commit comments

Comments
 (0)