Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DependencyInjection] Do not add return in LazyClosure when return type of closure is void #51251

Merged
merged 1 commit into from Aug 3, 2023

Conversation

ruudk
Copy link
Contributor

@ruudk ruudk commented Aug 3, 2023

Q A
Branch? 6.3
Bug fix? yes
New feature? no
Deprecations? no
Tickets
License MIT
Doc PR

The LazyClosure was introduced in #49639 and generates PHP code using reflection.

It works, but when the callable has a void return type, it would produce code like this:

return $container->services['closure2'] = (new class(fn() => new \Symfony\Component\DependencyInjection\Tests\Compiler\FooVoid()) extends \Symfony\Component\DependencyInjection\Argument\LazyClosure {
    public function __invoke(string $name) : void
    {
        // the `return` below causes the error
        return $this->service->__invoke(...\func_get_args());
    }
})->__invoke(...);

That return statement before calling the $this->service is not allowed and causes an error:

Compile Error: A void function must not return a value

/cc @nicolas-grekas

@carsonbot carsonbot added this to the 6.3 milestone Aug 3, 2023
@ruudk ruudk force-pushed the lazy-closure-void branch 2 times, most recently from c06e574 to 2cab4b7 Compare August 3, 2023 11:07
@carsonbot carsonbot changed the title Do not add return in LazyClosure when return type of closure is void [DependencyInjection] Do not add return in LazyClosure when return type of closure is void Aug 3, 2023
@nicolas-grekas
Copy link
Member

Thank you @ruudk.

@nicolas-grekas nicolas-grekas merged commit bbb5f5c into symfony:6.3 Aug 3, 2023
4 of 8 checks passed
@ruudk ruudk deleted the lazy-closure-void branch August 3, 2023 11:41
@fabpot fabpot mentioned this pull request Aug 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants