From c75fb14be148862ab345a0875d4a8133abc75f30 Mon Sep 17 00:00:00 2001 From: tianfenghan Date: Tue, 14 Jul 2026 16:03:36 +0800 Subject: [PATCH] feat(compiler): extend multi-return tuple to support three values - Modified multi_return_repeated_value function to return three values instead of two - Updated variable assignment to include $tail value in return statement - Changed destructuring assignment to handle three returned values - Updated expected output in test cases to include the additional tail value - Modified PHPUnit test assertions to match new three --- phpunit/code/multi-return-tuple.php | 3 ++- phpunit/src/MultiReturnTest.php | 5 +++-- tests/compiler/array/multi-return-move-production.phpt | 8 +++++--- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/phpunit/code/multi-return-tuple.php b/phpunit/code/multi-return-tuple.php index 28bb3861..9113781c 100644 --- a/phpunit/code/multi-return-tuple.php +++ b/phpunit/code/multi-return-tuple.php @@ -23,7 +23,8 @@ function phpunit_multi_three_values(): array function phpunit_multi_repeated_value(): array { $repeated = 'value'; - return [$repeated, $repeated]; + $tail = 'tail'; + return [$repeated, $repeated, $tail]; } function phpunit_multi_side_effect(): array diff --git a/phpunit/src/MultiReturnTest.php b/phpunit/src/MultiReturnTest.php index 7daf1c95..80f6a227 100644 --- a/phpunit/src/MultiReturnTest.php +++ b/phpunit/src/MultiReturnTest.php @@ -32,9 +32,10 @@ final class MultiReturnTest extends TestCase $code, ); $this->assertMatchesRegularExpression( - '/std::tuple (tmp_var_\\d+);\\s*' + '/std::tuple (tmp_var_\\d+);\\s*' . 'std::get<0>\\(\\1\\) = repeated;\\s*' - . 'std::get<1>\\(\\1\\) = std::move\\(repeated\\);/', + . 'std::get<1>\\(\\1\\) = std::move\\(repeated\\);\\s*' + . 'std::get<2>\\(\\1\\) = std::move\\(tail\\);/', $code, ); $this->assertStringContainsString( diff --git a/tests/compiler/array/multi-return-move-production.phpt b/tests/compiler/array/multi-return-move-production.phpt index 5ccd6811..09190ffb 100644 --- a/tests/compiler/array/multi-return-move-production.phpt +++ b/tests/compiler/array/multi-return-move-production.phpt @@ -14,7 +14,8 @@ function multi_return_owned_values(): array function multi_return_repeated_value(): array { $value = ['repeated']; - return [$value, $value]; + $tail = 'tail'; + return [$value, $value, $tail]; } function multi_return_reference_value(&$value): array @@ -43,9 +44,9 @@ function main(): void [$text, $array, $object] = multi_return_owned_values(); var_dump($text, $array, $object->value); - [$first, $second] = multi_return_repeated_value(); + [$first, $second, $tail] = multi_return_repeated_value(); $first[] = 'changed'; - var_dump($first, $second); + var_dump($first, $second, $tail); $source = 'reference'; [$referenceFirst, $referenceSecond] = multi_return_reference_value($source); @@ -84,6 +85,7 @@ array(1) { [0]=> string(8) "repeated" } +string(4) "tail" string(9) "reference" string(7) "changed" string(9) "reference"