Retain fixed arguments in func_get_args for variadic functions (#109)
* Fix lost fixed arguments in variadic func_get_args * Fix closing tag in variadic argument PHPT fixturemaster
parent
41c4a578dd
commit
62ec66bb6c
5 changed files with 57 additions and 5 deletions
@ -0,0 +1,2 @@ |
|||||||
|
<?php |
||||||
|
function fixedAndVariadic($head, ...$tail): array { return func_get_args(); } |
||||||
@ -0,0 +1,21 @@ |
|||||||
|
<?php |
||||||
|
|
||||||
|
use TypePhp\CompilerTest; |
||||||
|
|
||||||
|
final class VariadicFixedArgumentsTest extends BaseTest |
||||||
|
{ |
||||||
|
public function testFixedArgumentsInitializeTheArrayBeforeVariadicMerge(): void |
||||||
|
{ |
||||||
|
global $translator; |
||||||
|
$compiler = CompilerTest::create(TYPEPHP_ROOT_PATH); |
||||||
|
$translator = $compiler; |
||||||
|
$source = TYPEPHP_ROOT_PATH . '/phpunit/code/variadic-fixed-arguments.php'; |
||||||
|
$compiler->addFiles([$source]); |
||||||
|
$compiler->prepareFile($source); |
||||||
|
$code = file_get_contents($compiler->convertFile($source)); |
||||||
|
self::assertMatchesRegularExpression( |
||||||
|
'/(tmp_var_\d+) = php::Array\{\s*head\s*\};\s*\1\.merge\(tail\);/', |
||||||
|
$code, |
||||||
|
); |
||||||
|
} |
||||||
|
} |
||||||
@ -0,0 +1,23 @@ |
|||||||
|
--TEST-- |
||||||
|
func_get_args retains fixed parameters before the variadic tail |
||||||
|
--FILE-- |
||||||
|
<?php |
||||||
|
function fixedAndTail($head, ...$tail): array { return func_get_args(); } |
||||||
|
function multipleFixed($first, $second, ...$tail): array { return func_get_args(); } |
||||||
|
function onlyTail(...$tail): array { return func_get_args(); } |
||||||
|
function changedFixed(&$head, ...$tail): array { $head = 7; return func_get_args(); } |
||||||
|
function main(): void { |
||||||
|
echo json_encode(fixedAndTail(1,2,3)), "\n"; |
||||||
|
echo json_encode(fixedAndTail(1)), "\n"; |
||||||
|
echo json_encode(multipleFixed('a','b',3,4)), "\n"; |
||||||
|
echo json_encode(onlyTail(1,2)), "\n"; |
||||||
|
$head = 1; |
||||||
|
echo json_encode(changedFixed($head,2,3)), ':', $head, "\n"; |
||||||
|
} |
||||||
|
?> |
||||||
|
--EXPECT-- |
||||||
|
[1,2,3] |
||||||
|
[1] |
||||||
|
["a","b",3,4] |
||||||
|
[1,2] |
||||||
|
[7,2,3]:7 |
||||||
Loading…
Reference in new issue