8000 Fixing autowiring collision failure by weaverryan · Pull Request #18039 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

Fixing autowiring collision failure #18039

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
Mar 10, 2016

Conversation

weaverryan
Copy link
Member
Q A
Branch master
Bug fix? yes (bug introduced in master)
New feature? no
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets none
License MIT
Doc PR n/a

In #17877, I introduced a bug: https://github.com/symfony/symfony/pull/17877/files#diff-62df969ae028c559d33ffd256de1ac49L200.

Namely, if some class cannot be autowired because there is an odd number of matching services, then it would autowire the last service found, instead of throwing an exception. The tests only tested even numbers, which is how it was missed. This fixes that.

Thanks!

// keep an array of all services matching this type
if (!isset($this->ambiguousServiceTypes[$type])) {
$this->ambiguousServiceTypes[$type] = array(
$this->types[$type],
Copy link
Member

Choose a reason for hiding this comment

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

Are we sure that there always is an entry in $this->types for $type? In set(), we later on explicitly do check for isset($this->types[$type]).

Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

In that case, the call to $this->types[$type] is always skipped because of if (!isset($this->ambiguousServiceTypes[$type])) { (the line you pointed out is in a isset($this->ambiguousServiceTypes[$type]) block).

@dunglas
Copy link
Member
dunglas commented Mar 7, 2016

👍

@fabpot
Copy link
Member
fabpot commented Mar 10, 2016

Thank you @weaverryan.

@fabpot fabpot merged commit 2aea337 into symfony:master Mar 10, 2016
fabpot added a commit that referenced this pull request Mar 10, 2016
This PR was merged into the 3.1-dev branch.

Discussion
----------

Fixing autowiring collision failure

| Q             | A
| ------------- | ---
| Branch        | master
| Bug fix?      | yes (bug introduced in master)
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | none
| License       | MIT
| Doc PR        | n/a

In #17877, I introduced a bug: https://github.com/symfony/symfony/pull/17877/files#diff-62df969ae028c559d33ffd256de1ac49L200.

Namely, if some class cannot be autowired because there is an *odd* number of matching services, then it *would* autowire the last service found, instead of throwing an exception. The tests only tested even numbers, which is how it was missed. This fixes that.

Thanks!

Commits
-------

2aea337 Fixing a bug where an odd number of type collisions would incorrectly autowire (instead of an error)
@weaverryan weaverryan deleted the autowire-colission-fix branch March 11, 2016 01:34
@fabpot fabpot mentioned this pull request May 13, 2016
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
0