Skip to content

Commit cebf288

Browse files
committed
fix
1 parent 4f2baaf commit cebf288

2 files changed

Lines changed: 8 additions & 2 deletions

File tree

src/Type/IntersectionType.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -800,10 +800,11 @@ public function getLastIterableKeyType(): Type
800800

801801
public function getIterableValueType(): Type
802802
{
803+
$result = $this->intersectTypes(static fn (Type $type): Type => $type->getIterableValueType());
803804
if ($this->isCallable()->yes() && $this->isArray()->yes()) {
804-
return new UnionType([new ObjectWithoutClassType(), new StringType()]);
805+
return TypeCombinator::intersect($result, new UnionType([new ObjectWithoutClassType(), new StringType()]));
805806
}
806-
return $this->intersectTypes(static fn (Type $type): Type => $type->getIterableValueType());
807+
return $result;
807808
}
808809

809810
public function getFirstIterableValueType(): Type

tests/PHPStan/Rules/Methods/data/bug-14549.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@ public function doBar(array $list): void
3131
assertType('non-empty-list<string>&callable(): mixed&hasOffsetValue(0, non-empty-string)', $list);
3232
assertType('non-empty-string', $list[0]);
3333
assertType('string', $list[1]);
34+
35+
foreach($list as $k => $v) {
36+
assertType('0|1', $k);
37+
assertType('string', $v);
38+
}
3439
}
3540
}
3641
}

0 commit comments

Comments
 (0)