Skip to content

Commit

Permalink
bug #25203 [DI] Fix infinite loop in InlineServiceDefinitionsPass (ni…
Browse files Browse the repository at this point in the history
…colas-grekas)

This PR was merged into the 3.3 branch.

Discussion
----------

[DI] Fix infinite loop in InlineServiceDefinitionsPass

| Q             | A
| ------------- | ---
| Branch?       | 3.3
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | -
| License       | MIT
| Doc PR        | -

When a non-shared is involved in a setter-circular loop, the pass enters an infinite loop right now.

Commits
-------

b988aa7 [DI] Fix infinite loop in InlineServiceDefinitionsPass
  • Loading branch information
nicolas-grekas committed Nov 29, 2017
2 parents 020d78a + b988aa7 commit 85223d3
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
Expand Up @@ -61,10 +61,7 @@ protected function processValue($value, $isRoot = false)
$this->container->log($this, sprintf('Inlined service "%s" to "%s".', $id, $this->currentId));
$this->inlinedServiceIds[$id][] = $this->currentId;

if ($definition->isShared()) {
return $definition;
}
$value = clone $definition;
return $definition->isShared() ? $definition : clone $definition;
}
}

Expand Down
Expand Up @@ -92,6 +92,25 @@ public function testProcessDoesInlineNonSharedService()
$this->assertNotSame($container->getDefinition('bar'), $arguments[2]);
}

public function testProcessInlinesMixedServicesLoop()
{
$container = new ContainerBuilder();
$container
->register('foo')
->addArgument(new Reference('bar'))
->setShared(false)
;
$container
->register('bar')
->setPublic(false)
->addMethodCall('setFoo', array(new Reference('foo')))
;

$this->process($container);

$this->assertEquals($container->getDefinition('foo')->getArgument(0), $container->getDefinition('bar'));
}

public function testProcessInlinesIfMultipleReferencesButAllFromTheSameDefinition()
{
$container = new ContainerBuilder();
Expand Down

0 comments on commit 85223d3

Please sign in to comment.