Skip to content

Commit

Permalink
Make ConstantArrayType::getOffsetType most likely a bit more correct
Browse files Browse the repository at this point in the history
  • Loading branch information
herndlm committed Jul 13, 2022
1 parent e994f69 commit b51b928
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/Type/Constant/ConstantArrayType.php
Expand Up @@ -540,13 +540,16 @@ public function getOffsetType(Type $offsetValueType): Type
return $traverse($type);
}

$offsetType = new NeverType();
foreach ($this->valueTypes as $i => $valueType) {
if ($valueType->equals($type)) {
return $this->keyTypes[$i];
if (!$type->isSuperTypeOf($valueType)->yes()) {
continue;
}

$offsetType = TypeCombinator::union($offsetType, $this->keyTypes[$i]);
}

return new ErrorType(); // undefined offset value
return $offsetType instanceof NeverType ? new ErrorType() : $offsetType;
});
}

Expand Down

0 comments on commit b51b928

Please sign in to comment.