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
pull/20/head
韩天峰 1 month ago
parent aba8d9194d
commit c75fb14be1
  1. 3
      phpunit/code/multi-return-tuple.php
  2. 5
      phpunit/src/MultiReturnTest.php
  3. 8
      tests/compiler/array/multi-return-move-production.phpt

@ -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

@ -32,9 +32,10 @@ final class MultiReturnTest extends TestCase
$code,
);
$this->assertMatchesRegularExpression(
'/std::tuple<php::Var, php::Var> (tmp_var_\\d+);\\s*'
'/std::tuple<php::Var, php::Var, php::Var> (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(

@ -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"

Loading…
Cancel
Save