Skip to content

Container lint command fails with synthetic service+expression language combo #35691

@HypeMC

Description

@HypeMC

Symfony version(s) affected: 4.4

Description
The container lint command fails when using a combination of synthetic services & the expression language. I've created an example application to demonstrate the problem, all the code needed to reproduce the bug is in this commit: https://github.com/HypeMC/sf-container-lint-bug/commit/bb342d5b68892609fa86a048ce61f1750d0be6ab.

Basically the problem is that when using the service function from the expression language with a service which it self requires a synthetic service, the lint command fails, even though the service definitions are valid. The following error message is outputed:

In ContainerBuilder.php line 1091:
                                                                                                           
  You have requested a synthetic service ("kernel"). The DIC does not know how to construct this service.

How to reproduce

# config/services.yaml

    App\Controller\TestController:
        arguments:
            - '@=service("App\\Service\\Test").getSomething()'
class TestController extends AbstractController
{
    private $string;

    public function __construct(string $string)
    {
        $this->string = $string;
    }

    /**
     * @Route("/", name="test")
     */
    public function index(): Response
    {
        return new Response($this->string);
    }
}

class Test
{
    private $kernel;

    public function __construct(KernelInterface $kernel)
    {
        $this->kernel = $kernel;
    }

    public function getSomething(): string
    {
        return 'some-string';
    }
}

Additional context
image

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions