-
-
Notifications
You must be signed in to change notification settings - Fork 947
False positives on array access on iterable property with PHPDoc type that allows it #6243
Copy link
Copy link
Closed
phpstan/phpstan-src
#1860Labels
Description
Bug report
Given a property with native type iterable and PHPDoc type that allows array access, e.g. array, reading or writing to this property using array access is reported as an error.
Code snippet that reproduces the problem
<?php
class Foo
{
/** @var list<string>|(\ArrayAccess<int, string>&iterable<int, string>) */
private iterable $values;
/**
* @param list<string> $values
*/
public function update(array $values): void {
foreach ($this->values as $key => $_) {
unset($this->values[$key]);
}
foreach ($values as $value) {
$this->values[] = $value;
}
}
}PHPStan reports the following errors:
13 | Cannot access offset int on (ArrayAccess<int, string>&iterable<int, string>)\|iterable<int, string>.
-- | --
17 | Cannot access an offset on iterable<int, string>.
Expected output
No errors
Reactions are currently unavailable