Skip to content

[DI] Shared services should not be inlined in non-shared ones #27265

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

Merged
merged 1 commit into from
May 15, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,6 @@ private function isInlineableDefinition($id, Definition $definition, ServiceRefe
return false;
}

return true;
return $this->container->getDefinition($ids[0])->isShared();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Look like this change break the compilation with Undefined offset: 0 when the node doesn't have any InEdges

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hotfixed in 5eb17e5
but I don't understand how this can happen logically (we're here because we did find a reference to the service, to it must have at least one in-edge.)
could you share a reproduder?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The use case is: I use a custom TestKernel which inject mocks in the container and set the service as Synthetic with a compiler pass

NB: Changing the type of the compiler pass to PassConfig::TYPE_AFTER_REMOVING (to run after InlineServiceDefinitionsPass) fix the issue

This minimal reproduct case is:

class Kernel extends BaseKernel implements CompilerPassInterface
{
    // ...
    public function process(ContainerBuilder $container)
    {
        // routing.resolver is just an example for the minimal reproduct case here
        $container->getDefinition('routing.resolver')->setPublic(true)->setSynthetic(true);
    }
}

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, so this means we are missing a check for synthetic service!
added in #27366

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public function testProcessDoesInlineNonSharedService()
$this->assertNotSame($container->getDefinition('bar'), $arguments[2]);
}

public function testProcessInlinesMixedServicesLoop()
public function testProcessDoesNotInlineMixedServicesLoop()
{
$container = new ContainerBuilder();
$container
Expand All @@ -108,7 +108,7 @@ public function testProcessInlinesMixedServicesLoop()

$this->process($container);

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

/**
Expand Down