1
0
mirror of https://github.com/danog/psalm.git synced 2024-11-26 20:34:47 +01:00

Interpret variadic params as arrays

This commit is contained in:
Matthew Brown 2016-10-29 20:50:24 -04:00
parent ab131e3075
commit 95be3c4a05
2 changed files with 31 additions and 0 deletions

View File

@ -571,6 +571,18 @@ abstract class FunctionLikeChecker implements StatementsSource
} }
$param_type = Type::parseString($param_type_string); $param_type = Type::parseString($param_type_string);
if ($param->variadic) {
$param_type = new Type\Union([
new Type\GenericArray(
'array',
[
Type::getInt(),
$param_type
]
)
]);
}
} }
} }

View File

@ -93,6 +93,25 @@ class Php56Test extends PHPUnit_Framework_TestCase
$file_checker->check(true, true, $context); $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() public function testArgumentUnpacking()
{ {
$stmts = self::$_parser->parse('<?php $stmts = self::$_parser->parse('<?php