Skip to content
20 changes: 20 additions & 0 deletions src/Type/ArrayType.php
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,26 @@
}
}

if (
$this->itemType->isArray()->yes()

Check warning on line 414 in src/Type/ArrayType.php

View workflow job for this annotation

GitHub Actions / Mutation Testing (8.4, ubuntu-latest)

Escaped Mutant for Mutator "PHPStan\Infection\TrinaryLogicMutator": @@ @@ } if ( - $this->itemType->isArray()->yes() + !$this->itemType->isArray()->no() && !$this->itemType->isConstantArray()->yes() && $valueType->isArray()->yes() && !$valueType->isConstantArray()->yes()

Check warning on line 414 in src/Type/ArrayType.php

View workflow job for this annotation

GitHub Actions / Mutation Testing (8.3, ubuntu-latest)

Escaped Mutant for Mutator "PHPStan\Infection\TrinaryLogicMutator": @@ @@ } if ( - $this->itemType->isArray()->yes() + !$this->itemType->isArray()->no() && !$this->itemType->isConstantArray()->yes() && $valueType->isArray()->yes() && !$valueType->isConstantArray()->yes()
&& !$this->itemType->isConstantArray()->yes()

Check warning on line 415 in src/Type/ArrayType.php

View workflow job for this annotation

GitHub Actions / Mutation Testing (8.4, ubuntu-latest)

Escaped Mutant for Mutator "PHPStan\Infection\TrinaryLogicMutator": @@ @@ if ( $this->itemType->isArray()->yes() - && !$this->itemType->isConstantArray()->yes() + && $this->itemType->isConstantArray()->no() && $valueType->isArray()->yes() && !$valueType->isConstantArray()->yes() && $this->itemType->getIterableValueType()->isArray()->yes()

Check warning on line 415 in src/Type/ArrayType.php

View workflow job for this annotation

GitHub Actions / Mutation Testing (8.3, ubuntu-latest)

Escaped Mutant for Mutator "PHPStan\Infection\TrinaryLogicMutator": @@ @@ if ( $this->itemType->isArray()->yes() - && !$this->itemType->isConstantArray()->yes() + && $this->itemType->isConstantArray()->no() && $valueType->isArray()->yes() && !$valueType->isConstantArray()->yes() && $this->itemType->getIterableValueType()->isArray()->yes()
&& $valueType->isArray()->yes()

Check warning on line 416 in src/Type/ArrayType.php

View workflow job for this annotation

GitHub Actions / Mutation Testing (8.4, ubuntu-latest)

Escaped Mutant for Mutator "PHPStan\Infection\TrinaryLogicMutator": @@ @@ if ( $this->itemType->isArray()->yes() && !$this->itemType->isConstantArray()->yes() - && $valueType->isArray()->yes() + && !$valueType->isArray()->no() && !$valueType->isConstantArray()->yes() && $this->itemType->getIterableValueType()->isArray()->yes() && $valueType->getIterableValueType()->isArray()->yes()

Check warning on line 416 in src/Type/ArrayType.php

View workflow job for this annotation

GitHub Actions / Mutation Testing (8.3, ubuntu-latest)

Escaped Mutant for Mutator "PHPStan\Infection\TrinaryLogicMutator": @@ @@ if ( $this->itemType->isArray()->yes() && !$this->itemType->isConstantArray()->yes() - && $valueType->isArray()->yes() + && !$valueType->isArray()->no() && !$valueType->isConstantArray()->yes() && $this->itemType->getIterableValueType()->isArray()->yes() && $valueType->getIterableValueType()->isArray()->yes()
&& !$valueType->isConstantArray()->yes()

Check warning on line 417 in src/Type/ArrayType.php

View workflow job for this annotation

GitHub Actions / Mutation Testing (8.4, ubuntu-latest)

Escaped Mutant for Mutator "PHPStan\Infection\TrinaryLogicMutator": @@ @@ $this->itemType->isArray()->yes() && !$this->itemType->isConstantArray()->yes() && $valueType->isArray()->yes() - && !$valueType->isConstantArray()->yes() + && $valueType->isConstantArray()->no() && $this->itemType->getIterableValueType()->isArray()->yes() && $valueType->getIterableValueType()->isArray()->yes() ) {

Check warning on line 417 in src/Type/ArrayType.php

View workflow job for this annotation

GitHub Actions / Mutation Testing (8.3, ubuntu-latest)

Escaped Mutant for Mutator "PHPStan\Infection\TrinaryLogicMutator": @@ @@ $this->itemType->isArray()->yes() && !$this->itemType->isConstantArray()->yes() && $valueType->isArray()->yes() - && !$valueType->isConstantArray()->yes() + && $valueType->isConstantArray()->no() && $this->itemType->getIterableValueType()->isArray()->yes() && $valueType->getIterableValueType()->isArray()->yes() ) {
&& $this->itemType->getIterableValueType()->isArray()->yes()

Check warning on line 418 in src/Type/ArrayType.php

View workflow job for this annotation

GitHub Actions / Mutation Testing (8.4, ubuntu-latest)

Escaped Mutant for Mutator "PHPStan\Infection\TrinaryLogicMutator": @@ @@ && !$this->itemType->isConstantArray()->yes() && $valueType->isArray()->yes() && !$valueType->isConstantArray()->yes() - && $this->itemType->getIterableValueType()->isArray()->yes() + && !$this->itemType->getIterableValueType()->isArray()->no() && $valueType->getIterableValueType()->isArray()->yes() ) { $newItemType = $this->itemType->setExistingOffsetValueType(

Check warning on line 418 in src/Type/ArrayType.php

View workflow job for this annotation

GitHub Actions / Mutation Testing (8.3, ubuntu-latest)

Escaped Mutant for Mutator "PHPStan\Infection\TrinaryLogicMutator": @@ @@ && !$this->itemType->isConstantArray()->yes() && $valueType->isArray()->yes() && !$valueType->isConstantArray()->yes() - && $this->itemType->getIterableValueType()->isArray()->yes() + && !$this->itemType->getIterableValueType()->isArray()->no() && $valueType->getIterableValueType()->isArray()->yes() ) { $newItemType = $this->itemType->setExistingOffsetValueType(
&& $valueType->getIterableValueType()->isArray()->yes()

Check warning on line 419 in src/Type/ArrayType.php

View workflow job for this annotation

GitHub Actions / Mutation Testing (8.4, ubuntu-latest)

Escaped Mutant for Mutator "PHPStan\Infection\TrinaryLogicMutator": @@ @@ && $valueType->isArray()->yes() && !$valueType->isConstantArray()->yes() && $this->itemType->getIterableValueType()->isArray()->yes() - && $valueType->getIterableValueType()->isArray()->yes() + && !$valueType->getIterableValueType()->isArray()->no() ) { $newItemType = $this->itemType->setExistingOffsetValueType( $valueType->getIterableKeyType(),

Check warning on line 419 in src/Type/ArrayType.php

View workflow job for this annotation

GitHub Actions / Mutation Testing (8.3, ubuntu-latest)

Escaped Mutant for Mutator "PHPStan\Infection\TrinaryLogicMutator": @@ @@ && $valueType->isArray()->yes() && !$valueType->isConstantArray()->yes() && $this->itemType->getIterableValueType()->isArray()->yes() - && $valueType->getIterableValueType()->isArray()->yes() + && !$valueType->getIterableValueType()->isArray()->no() ) { $newItemType = $this->itemType->setExistingOffsetValueType( $valueType->getIterableKeyType(),
) {
$newItemType = $this->itemType->setExistingOffsetValueType(
$valueType->getIterableKeyType(),
$valueType->getIterableValueType(),
);
if ($newItemType !== $this->itemType) {
return new self(
$this->keyType,
$newItemType,
);
}
}

return new self(
$this->keyType,
TypeCombinator::union($this->itemType, $valueType),
Expand Down
108 changes: 108 additions & 0 deletions tests/PHPStan/Analyser/nsrt/bug-13637.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
<?php declare(strict_types = 1);

namespace Bug13637;

use function PHPStan\Testing\assertType;

/**
* @return array<int, array<int, array<int, array{abc: int, def: int, ghi: int}>>>
*/
function doesNotWork() : array {
$final = [];

for ($i = 0; $i < 5; $i++) {
$j = $i * 2;
$k = $j +1;
$l = $i * 3;
$final[$i][$j][$k]['abc'] = $i;
$final[$i][$j][$k]['def'] = $i;
$final[$i][$j][$k]['ghi'] = $i;

assertType("array{abc: int<0, 4>, def: int<0, 4>, ghi: int<0, 4>}", $final[$i][$j][$k]);
}

return $final;
}

/**
* @return array<int, array<int, array<int, array<int, array{abc: int, def: int, ghi: int}>>>>
*/
function fourLevelsDeep() : array {
$final = [];

for ($i = 0; $i < 5; $i++) {
$j = $i * 2;
$k = $j + 1;
$l = $i * 3;
$final[$i][$j][$k][$l]['abc'] = $i;
$final[$i][$j][$k][$l]['def'] = $i;
$final[$i][$j][$k][$l]['ghi'] = $i;

assertType("array{abc: int<0, 4>, def: int<0, 4>, ghi: int<0, 4>}", $final[$i][$j][$k][$l]);
}

return $final;
}

/**
* @return array<int, array<int, array<int, array<int, array<int, array{abc: int, def: int, ghi: int}>>>>>
*/
function fiveLevelsDeep() : array {
$final = [];

for ($i = 0; $i < 5; $i++) {
$j = $i * 2;
$k = $j + 1;
$l = $i * 3;
$m = $i + 10;
$final[$i][$j][$k][$l][$m]['abc'] = $i;
$final[$i][$j][$k][$l][$m]['def'] = $i;
$final[$i][$j][$k][$l][$m]['ghi'] = $i;

assertType("array{abc: int<0, 4>, def: int<0, 4>, ghi: int<0, 4>}", $final[$i][$j][$k][$l][$m]);
}

return $final;
}

/**
* @return array<int, array<int, array<int, array<int, array<int, array<int, array{abc: int, def: int, ghi: int}>>>>>>
*/
function sixLevelsDeep() : array {
$final = [];

for ($i = 0; $i < 5; $i++) {
$j = $i * 2;
$k = $j + 1;
$l = $i * 3;
$m = $i + 10;
$n = $i + 20;
$final[$i][$j][$k][$l][$m][$n]['abc'] = $i;
$final[$i][$j][$k][$l][$m][$n]['def'] = $i;
$final[$i][$j][$k][$l][$m][$n]['ghi'] = $i;

assertType("array{abc: int<0, 4>, def: int<0, 4>, ghi: int<0, 4>}", $final[$i][$j][$k][$l][$m][$n]);
}

return $final;
}

/**
* @return array<int, array<int, array{abc: int, def: int, ghi: int}>>
*/
function thisWorks() : array {
$final = [];

for ($i = 0; $i < 5; $i++) {
$j = $i * 2;
$k = $j +1;
$l = $i * 3;
$final[$i][$j]['abc'] = $i;
$final[$i][$j]['def'] = $i;
$final[$i][$j]['ghi'] = $i;

assertType("array{abc: int<0, 4>, def: int<0, 4>, ghi: int<0, 4>}", $final[$i][$j]);
}

return $final;
}
Loading