mirror of
https://github.com/danog/psalm.git
synced 2024-11-30 04:39:00 +01:00
Add support for variadic and packed variables
This commit is contained in:
parent
58bb10b948
commit
451d97e0ed
@ -566,7 +566,7 @@ abstract class FunctionLikeChecker implements StatementsSource
|
||||
$param_type ?: Type::getMixed(),
|
||||
$is_optional,
|
||||
$is_nullable,
|
||||
$param->getLine()
|
||||
$param->variadic
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -3659,11 +3659,29 @@ class StatementsChecker
|
||||
$cased_method_id = MethodChecker::getCasedMethodId($method_id);
|
||||
}
|
||||
|
||||
if ($function_params) {
|
||||
foreach ($function_params as $function_param) {
|
||||
$is_variadic = $is_variadic || $function_param->is_variadic;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$has_packed_var = false;
|
||||
|
||||
foreach ($args as $arg) {
|
||||
$has_packed_var = $has_packed_var || $arg->unpack;
|
||||
}
|
||||
|
||||
foreach ($args as $argument_offset => $arg) {
|
||||
if ($method_id && isset($arg->value->inferredType)) {
|
||||
if (count($function_params) > $argument_offset) {
|
||||
$param_type = $function_params[$argument_offset]->type;
|
||||
|
||||
// for now stop when we encounter a variadic param pr a packed argument
|
||||
if ($function_params[$argument_offset]->is_variadic || $arg->unpack) {
|
||||
break;
|
||||
}
|
||||
|
||||
if ($this->checkFunctionArgumentType(
|
||||
$arg->value->inferredType,
|
||||
$param_type,
|
||||
@ -3693,11 +3711,11 @@ class StatementsChecker
|
||||
return;
|
||||
}
|
||||
|
||||
if (count($args) < count($function_params)) {
|
||||
if (!$has_packed_var && count($args) < count($function_params)) {
|
||||
for ($i = count($args); $i < count($function_params); $i++) {
|
||||
$param = $function_params[$i];
|
||||
|
||||
if (!$param->is_optional) {
|
||||
if (!$param->is_optional && !$param->is_variadic) {
|
||||
if (IssueBuffer::accepts(
|
||||
new TooFewArguments('Too few arguments for method ' . $cased_method_id, $this->checked_file_name, $line_number),
|
||||
$this->suppressed_issues
|
||||
|
@ -31,9 +31,9 @@ class FunctionLikeParameter
|
||||
* @param Type\Union $type
|
||||
* @param boolean $is_optional
|
||||
* @param boolean $is_nullable
|
||||
* @param int $line_number
|
||||
* @param boolean $is_variadic
|
||||
*/
|
||||
public function __construct($name, $by_ref, Type\Union $type, $is_optional = true, $is_nullable = false, $line_number = -1)
|
||||
public function __construct($name, $by_ref, Type\Union $type, $is_optional = true, $is_nullable = false, $is_variadic = false)
|
||||
{
|
||||
$this->name = $name;
|
||||
$this->by_ref = $by_ref;
|
||||
@ -41,5 +41,6 @@ class FunctionLikeParameter
|
||||
$this->signature_type = $type;
|
||||
$this->is_optional = $is_optional;
|
||||
$this->is_nullable = $is_nullable;
|
||||
$this->is_variadic = $is_variadic;
|
||||
}
|
||||
}
|
||||
|
@ -123,6 +123,8 @@ class Php56Test extends PHPUnit_Framework_TestCase
|
||||
|
||||
public function testUse()
|
||||
{
|
||||
$this->markTestIncomplete('This passes, but I think there‘s cheating afoot');
|
||||
|
||||
$stmts = self::$_parser->parse('<?php
|
||||
namespace Name\Space {
|
||||
const FOO = 42;
|
||||
|
Loading…
Reference in New Issue
Block a user