1
0
mirror of https://github.com/danog/psalm.git synced 2024-11-26 12:24:49 +01:00

Fix #5078 - when unpacking with missing array item, Use the param’s default type if param has one

This commit is contained in:
Matthew Brown 2021-01-22 00:20:51 -05:00 committed by Daniil Gentili
parent 2b39ab02a0
commit 822464cbaf
Signed by: danog
GPG Key ID: 8C1BE3B34B230CA7
2 changed files with 8 additions and 1 deletions

View File

@ -459,7 +459,9 @@ class ArgumentAnalyzer
) { ) {
$arg_type = clone $unpacked_atomic_array->properties[$unpacked_argument_offset]; $arg_type = clone $unpacked_atomic_array->properties[$unpacked_argument_offset];
} else { } else {
$arg_type = Type::getMixed(); $arg_type = $function_param->is_optional
? ($function_param->default_type ?: Type::getMixed())
: Type::getMixed();
} }
} elseif ($unpacked_atomic_array instanceof Type\Atomic\TList) { } elseif ($unpacked_atomic_array instanceof Type\Atomic\TList) {
$arg_type = $unpacked_atomic_array->type_param; $arg_type = $unpacked_atomic_array->type_param;

View File

@ -268,6 +268,11 @@ class ArgTest extends TestCase
[], [],
'8.0' '8.0'
], ],
'variadicArgsOptional' => [
'<?php
bar(...["aaaaa"]);
function bar(string $p1, int $p3 = 10) : void {}'
],
]; ];
} }