mirror of
https://github.com/danog/psalm.git
synced 2024-12-02 09:37:59 +01:00
Don’t give up when faced with variadic type
This commit is contained in:
parent
b9bad01dbd
commit
e4769fd04a
@ -1082,13 +1082,29 @@ class CallChecker
|
|||||||
$has_packed_var = $has_packed_var || $arg->unpack;
|
$has_packed_var = $has_packed_var || $arg->unpack;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$last_param = $function_params
|
||||||
|
? $function_params[count($function_params) - 1]
|
||||||
|
: null;
|
||||||
|
|
||||||
foreach ($args as $argument_offset => $arg) {
|
foreach ($args as $argument_offset => $arg) {
|
||||||
if ($function_params !== null && isset($arg->value->inferredType)) {
|
if ($function_params !== null && isset($arg->value->inferredType)) {
|
||||||
if (count($function_params) > $argument_offset) {
|
$function_param = count($function_params) > $argument_offset
|
||||||
$param_type = $function_params[$argument_offset]->type;
|
? $function_params[$argument_offset]
|
||||||
|
: ($last_param && $last_param->is_variadic ? $last_param : null);
|
||||||
|
|
||||||
// for now stop when we encounter a variadic param pr a packed argument
|
if ($function_param) {
|
||||||
if ($function_params[$argument_offset]->is_variadic || $arg->unpack) {
|
$param_type = $function_param->type;
|
||||||
|
|
||||||
|
if ($function_param->is_variadic) {
|
||||||
|
if (!$param_type->hasArray() || !$param_type->types['array'] instanceof TArray) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
$param_type = clone $param_type->types['array']->type_params[1];
|
||||||
|
}
|
||||||
|
|
||||||
|
// for now stop when we encounter a packed argument
|
||||||
|
if ($arg->unpack) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -142,6 +142,27 @@ class Php56Test extends PHPUnit_Framework_TestCase
|
|||||||
$file_checker->visitAndAnalyzeMethods($context);
|
$file_checker->visitAndAnalyzeMethods($context);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @expectedException \Psalm\Exception\CodeException
|
||||||
|
* @expectedExceptionMessage InvalidScalarArgument
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testVariadicArrayBadParam()
|
||||||
|
{
|
||||||
|
$stmts = self::$parser->parse('<?php
|
||||||
|
/**
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
function f(int ...$a_list) {
|
||||||
|
}
|
||||||
|
f(1, 2, "3");
|
||||||
|
');
|
||||||
|
|
||||||
|
$file_checker = new FileChecker('somefile.php', $this->project_checker, $stmts);
|
||||||
|
$context = new Context();
|
||||||
|
$file_checker->visitAndAnalyzeMethods($context);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
|
Loading…
Reference in New Issue
Block a user