Skip to content

Commit eef18c8

Browse files
committed
Fix t::shape inference when tuple has possibly undefined keys
1 parent 0d6787a commit eef18c8

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

src/Integration/Hook/ShapeReturnTypeProvider.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,16 +31,23 @@ public static function getMethodReturnType(MethodReturnTypeProviderEvent $event)
3131
->flatMap(fn($union) => Psalm::asSingleAtomicOf(Type\Atomic\TKeyedArray::class, $union));
3232

3333
$remapped = [];
34+
$all_keys_defined = true;
3435

3536
foreach ($arg_type->properties as $key => $type) {
36-
$remapped[$key] = yield Option::some($type)
37+
$type = yield Option::some($type)
3738
->flatMap(fn($union) => Psalm::asSingleAtomicOf(Type\Atomic\TGenericObject::class, $union))
3839
->flatMap(fn($generic) => Psalm::getTypeParam($generic, StaticTypeInterface::class, position: 0));
40+
41+
if ($type->possibly_undefined) {
42+
$all_keys_defined = false;
43+
}
44+
45+
$remapped[$key] = $type;
3946
}
4047

4148
$keyed_array = new Type\Atomic\TKeyedArray($remapped);
4249
$keyed_array->sealed = $arg_type->sealed;
43-
$keyed_array->is_list = $arg_type->is_list;
50+
$keyed_array->is_list = $all_keys_defined ? $arg_type->is_list : false;
4451

4552
return new Type\Union([
4653
new Type\Atomic\TGenericObject(StaticTypeInterface::class, [

0 commit comments

Comments
 (0)