From 317c69d0ff930f927a824ff71c505fd746d1b519 Mon Sep 17 00:00:00 2001 From: Ruud Kamphuis Date: Thu, 26 Sep 2024 16:07:09 +0200 Subject: [PATCH] Replace `return; yield` with yield from `[]` See #4259 --- src/Node/ForNode.php | 2 +- tests/Fixtures/tags/for/loop_in_else.test | 2 +- tests/Node/ForTest.php | 10 +++++----- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/Node/ForNode.php b/src/Node/ForNode.php index 5541eaa0a..cac048172 100644 --- a/src/Node/ForNode.php +++ b/src/Node/ForNode.php @@ -93,7 +93,7 @@ class ForNode extends Node $compiler->write("\$context = array_intersect_key(\$context, \$$parentVar) + \$$parentVar;\n"); $compiler - ->write("return; yield;\n") + ->write("yield from [];\n") ->outdent() ->write("};\n") ->write("\Closure::bind(\$$functionVar, \$this, self::class);\n") diff --git a/tests/Fixtures/tags/for/loop_in_else.test b/tests/Fixtures/tags/for/loop_in_else.test index abc8bf19f..14d90989a 100644 --- a/tests/Fixtures/tags/for/loop_in_else.test +++ b/tests/Fixtures/tags/for/loop_in_else.test @@ -35,7 +35,7 @@ --DATA-- return [ 'empty_it' => new \EmptyIterator(), - 'yielding_it' => (function (): \Generator { return; yield; })(), + 'yielding_it' => (function (): \Generator { yield from []; })(), ] --EXPECT-- OK diff --git a/tests/Node/ForTest.php b/tests/Node/ForTest.php index 3c5907189..01f2b6090 100644 --- a/tests/Node/ForTest.php +++ b/tests/Node/ForTest.php @@ -76,7 +76,7 @@ class ForTest extends NodeTestCase } unset(\$context['key'], \$context['item']); \$context = array_intersect_key(\$context, \$__internal_compile_2) + \$__internal_compile_2; - return; yield; + yield from []; }; \Closure::bind(\$__internal_compile_1, \$this, self::class); yield from \$__internal_compile_1(\$__internal_compile_0, \$context, \$blocks, \$__internal_compile_1, 0); @@ -103,7 +103,7 @@ EOF } unset(\$context['k'], \$context['v'], \$context['loop']); \$context = array_intersect_key(\$context, \$__internal_compile_2) + \$__internal_compile_2; - return; yield; + yield from []; }; \Closure::bind(\$__internal_compile_1, \$this, self::class); yield from \$__internal_compile_1(\$__internal_compile_0, \$context, \$blocks, \$__internal_compile_1, 0); @@ -130,7 +130,7 @@ EOF } unset(\$context['k'], \$context['v'], \$context['loop']); \$context = array_intersect_key(\$context, \$__internal_compile_2) + \$__internal_compile_2; - return; yield; + yield from []; }; \Closure::bind(\$__internal_compile_1, \$this, self::class); yield from \$__internal_compile_1(\$__internal_compile_0, \$context, \$blocks, \$__internal_compile_1, 0); @@ -163,7 +163,7 @@ EOF } unset(\$context['k'], \$context['v'], \$context['loop']); \$context = array_intersect_key(\$context, \$__internal_compile_2) + \$__internal_compile_2; - return; yield; + yield from []; }; \Closure::bind(\$__internal_compile_1, \$this, self::class); yield from \$__internal_compile_1(\$__internal_compile_0, \$context, \$blocks, \$__internal_compile_1, 0); @@ -186,7 +186,7 @@ EOF } unset(\$context['_key'], \$context['item'], \$context['loop']); \$context = array_intersect_key(\$context, \$__internal_compile_2) + \$__internal_compile_2; - return; yield; + yield from []; }; \Closure::bind(\$__internal_compile_1, \$this, self::class); yield from \$__internal_compile_1(\$__internal_compile_0, \$context, \$blocks, \$__internal_compile_1, 0);