Skip to content

[DI] Fix inlining conflict by restricting IteratorArgument to Reference[] #22496

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
Apr 23, 2017

Conversation

nicolas-grekas
Copy link
Member

@nicolas-grekas nicolas-grekas commented Apr 21, 2017

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 -

Reference found in ArgumentInterface::getValue() are currently not inlined.
While trying to do so (hint: I failed), I noticed that the current code is broken for IteratorArgument which can contain anonymous Definition for now, which are then not inlined correctly.

This PR restricts IteratorArgument to arrays of Reference, and improves a few related things found while doing it.

(fabbot failure is false positive)

@@ -683,16 +684,19 @@ private function addService($id, Definition $definition)
$code .= sprintf(" @trigger_error(%s, E_USER_DEPRECATED);\n\n", $this->export($definition->getDeprecationMessage($id)));
}

$inlinedDefinitions = $this->getInlinedDefinitions($definition);
Copy link
Member Author

Choose a reason for hiding this comment

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

this replaces many calls to getInlinedDefinitions by a single one

@@ -1332,8 +1336,6 @@ private function getDefinitionsFromArguments(array $arguments)
foreach ($arguments as $argument) {
if (is_array($argument)) {
$definitions = array_merge($definitions, $this->getDefinitionsFromArguments($argument));
} elseif ($argument instanceof ArgumentInterface) {
$definitions = array_merge($definitions, $this->getDefinitionsFromArguments($argument->getValues()));
Copy link
Member Author

Choose a reason for hiding this comment

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

this is a bug, silent for now because we don't have inline definitions in $argument->getValues(), but still a logical mistake

@@ -1452,6 +1454,9 @@ private function dumpValue($value, $interpolate = true)
if ($value->getMethodCalls()) {
throw new RuntimeException('Cannot dump definitions which have method calls.');
}
if ($value->getProperties()) {
Copy link
Member Author

Choose a reason for hiding this comment

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

should be done on 2.7 also

Copy link
Member

Choose a reason for hiding this comment

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

then please split it in a separate PR

Copy link
Member Author

Choose a reason for hiding this comment

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

done in #22498

@@ -1452,6 +1454,9 @@ private function dumpValue($value, $interpolate = true)
if ($value->getMethodCalls()) {
throw new RuntimeException('Cannot dump definitions which have method calls.');
}
if ($value->getProperties()) {
Copy link
Member

Choose a reason for hiding this comment

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

then please split it in a separate PR

}

return new IteratorArgument($this->resolveServices($argument, $file, $isParameter));
try {
return new IteratorArgument($this->resolveServices($argument, $file, $isParameter));
Copy link
Member

Choose a reason for hiding this comment

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

IMO, resolveServices should be outside the try/catch, so that we don't replace its exceptions by mistake

Copy link
Member Author

Choose a reason for hiding this comment

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

good idea, done (also for the Xml loader, just in case)

@nicolas-grekas nicolas-grekas force-pushed the di-fix-inlined branch 3 times, most recently from 15f9711 to a67c3d7 Compare April 21, 2017 12:33
try {
$arguments[$key] = new IteratorArgument($arg);
} catch (InvalidArgumentException $e) {
throw new InvalidArgumentException(sprintf('Tag "<%s>" with type="iterator" only accepts collections of type="service" references.', $name));
Copy link
Member

@chalasr chalasr Apr 21, 2017

Choose a reason for hiding this comment

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

Tag => Argument? Attribute?

Copy link
Member Author

@nicolas-grekas nicolas-grekas Apr 21, 2017

Choose a reason for hiding this comment

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

It's an xml tag, eg Tag "<argument>" ... or Tag "<property>" ...

@fabpot
Copy link
Member

fabpot commented Apr 23, 2017

Thank you @nicolas-grekas.

@fabpot fabpot merged commit 4d3dce1 into symfony:master Apr 23, 2017
fabpot added a commit that referenced this pull request Apr 23, 2017
… to Reference[] (nicolas-grekas)

This PR was merged into the 3.3-dev branch.

Discussion
----------

[DI] Fix inlining conflict by restricting IteratorArgument to Reference[]

| 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        | -

`Reference` found in `ArgumentInterface::getValue()` are currently not inlined.
While trying to do so (hint: I failed), I noticed that the current code is broken for `IteratorArgument` which can contain anonymous `Definition` for now, which are then not inlined correctly.

This PR restricts `IteratorArgument` to arrays of `Reference`, and improves a few related things found while doing it.

(fabbot failure is false positive)

Commits
-------

4d3dce1 [DI] Fix inlining conflict by restricting IteratorArgument to Reference[]
@nicolas-grekas nicolas-grekas deleted the di-fix-inlined branch April 25, 2017 17:43
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.

5 participants