Skip to content

lint:container does not correctly validate tagged services in debug mode #53839

@DCoderLT

Description

@DCoderLT

Symfony version(s) affected

6.3

Description

When the console command lint:container is invoked in debug mode, it recompiles the container with many compiler passes removed, including ResolveTaggedIteratorArgumentPass and ServiceLocatorTagPass. As a result, RemoveUnusedDefinitionsPass sees no references to tagged services and removes them as “unused”, unless those services are made public or otherwise referenced in the container. After those services are removed, the CheckTypeDeclarationsPass pass does not see them and does not validate them.
The command behaves correctly in non-debug mode, but this is quite surprising and non-obvious.

How to reproduce

  • create a service that uses !tagged_iterator to find its supporting services
  • create another service, tag it so the first service will find it
  • intentionally configure incorrect arguments for this second service
  • run the lint:container console command
  • observe that it did not detect those incorrect arguments
  • mark the second service as public
  • re-run lint:container
  • observe that incorrect arguments are now correctly detected

Repro example: https://github.com/DCoderLT/symfony_issue_53839 , the last service in config/services.yaml is configured incorrectly, but lint:container does not detect it.

Possible Solution

If I add the ResolveTaggedIteratorArgumentPass and ServiceLocatorTagPass passes back into the linter command, the tagged services no longer get removed, so the bug gets fixed. But I am sure those passes were removed for a reason, and I don’t know if they depend on any other passes that have also been excluded from this command. So I am reluctant to suggest “add those two passes” as a complete/correct fix.
Removing RemoveUnusedDefinitionsPass also doesn’t seem like the correct fix.

Additional Context

No response

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