Skip to content

Commit

Permalink
Fix ConstantArrayType::hasOffsetValueType() for offset union type whe…
Browse files Browse the repository at this point in the history
…re all types are valid
  • Loading branch information
ondrejmirtes committed Apr 23, 2024
1 parent d4bf4f5 commit 26e949b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/Type/Constant/ConstantArrayType.php
Original file line number Diff line number Diff line change
Expand Up @@ -610,6 +610,14 @@ public function findTypeAndMethodNames(): array
public function hasOffsetValueType(Type $offsetType): TrinaryLogic
{
$offsetType = $offsetType->toArrayKey();
if ($offsetType instanceof UnionType) {
$results = [];
foreach ($offsetType->getTypes() as $innerType) {
$results[] = $this->hasOffsetValueType($innerType);
}

return TrinaryLogic::extremeIdentity(...$results);
}

$result = TrinaryLogic::createNo();
foreach ($this->keyTypes as $i => $keyType) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,14 @@ public function testConstantArray2(array $a): void
echo $a[0];
}
}

/**
* @param array{0: '9', A: 'Z', a: 'z'} $a
* @param '0'|'A'|'a' $dim
*/
public function testDimUnion(array $a, string $dim): void
{
echo $a[$dim];
}

}

0 comments on commit 26e949b

Please sign in to comment.