Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
1 change: 1 addition & 0 deletions src/Analyser/ExprHandler/AssignHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -991,6 +991,7 @@ private function produceArrayDimFetchAssignValueToWrite(array $dimFetchStack, ar
$offsetType !== null
&& $arrayDimFetch !== null
&& $scope->hasExpressionType($arrayDimFetch)->yes()
&& !$offsetValueType->hasOffsetValueType($offsetType)->no()
) {
$hasOffsetType = null;
if ($offsetType instanceof ConstantStringType || $offsetType instanceof ConstantIntegerType) {
Expand Down
2 changes: 1 addition & 1 deletion tests/PHPStan/Analyser/nsrt/bug-13270b-php8.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public function parseData(array $data): array
if (!array_key_exists('priceWithVat', $data['price'])) {
$data['price']['priceWithVat'] = null;
}
assertType("non-empty-array&hasOffset('priceWithVat')", $data['price']);
assertType("non-empty-array&hasOffsetValue('priceWithVat', mixed)", $data['price']);
if (!array_key_exists('priceWithoutVat', $data['price'])) {
$data['price']['priceWithoutVat'] = null;
}
Expand Down
20 changes: 20 additions & 0 deletions tests/PHPStan/Analyser/nsrt/bug-13786.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php declare(strict_types=1);

namespace Bug13786;

use function PHPStan\Testing\assertType;

/** @var array<mixed> $arr */

/** @var non-empty-list<'a'|'b'|'c'> $cols */

$total = [ ];
foreach ($arr as $id => $dummy) {
$total[$id] = [ ];
foreach ($cols as $col) {
$total[$id][$col] = '0';
}
assertType("non-empty-array<'a'|'b'|'c'|'d', '0'>", $total[$id]);
$total[$id]['d'] = '0';
assertType("non-empty-array<'a'|'b'|'c'|'d', '0'>&hasOffsetValue('d', '0')", $total[$id]);
}
Loading