mirror of
https://github.com/danog/psalm.git
synced 2024-11-30 04:39:00 +01:00
Interpret variadic params as arrays
This commit is contained in:
parent
ab131e3075
commit
95be3c4a05
@ -571,6 +571,18 @@ abstract class FunctionLikeChecker implements StatementsSource
|
||||
}
|
||||
|
||||
$param_type = Type::parseString($param_type_string);
|
||||
|
||||
if ($param->variadic) {
|
||||
$param_type = new Type\Union([
|
||||
new Type\GenericArray(
|
||||
'array',
|
||||
[
|
||||
Type::getInt(),
|
||||
$param_type
|
||||
]
|
||||
)
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -93,6 +93,25 @@ class Php56Test extends PHPUnit_Framework_TestCase
|
||||
$file_checker->check(true, true, $context);
|
||||
}
|
||||
|
||||
public function testVariadicArray()
|
||||
{
|
||||
$stmts = self::$_parser->parse('<?php
|
||||
function f(int ...$a_list) {
|
||||
return array_map(function (int $a) {
|
||||
return $a + 1;
|
||||
}, $a_list);
|
||||
}
|
||||
|
||||
f(1);
|
||||
f(1, 2);
|
||||
f(1, 2, 3);
|
||||
');
|
||||
|
||||
$file_checker = new \Psalm\Checker\FileChecker('somefile.php', $stmts);
|
||||
$context = new Context('somefile.php');
|
||||
$file_checker->check(true, true, $context);
|
||||
}
|
||||
|
||||
public function testArgumentUnpacking()
|
||||
{
|
||||
$stmts = self::$_parser->parse('<?php
|
||||
|
Loading…
Reference in New Issue
Block a user