Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[DependencyInjection] AddCheckAliasValidityPass to check interface compatibility#50745

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged

Conversation

@n-valverde
Copy link
Contributor

@n-valverden-valverde commentedJun 22, 2023
edited
Loading

QA
Branch?7.1
Bug fix?no
New feature?yes
Deprecations?no
Tickets/
LicenseMIT
Doc PRTODO

Hello, I would like to propose adding a pass to the compiler, to make sure that when defining an alias which happens to be an interface, the resolved service actually implements that interface. See example below.

<services>    <serviceid="a_vendor.service"class="Foo\Bar" />    <serviceid="Foo\BarInterface"alias="a_vendor.service" /></services>
namespaceFoo;interface BarInterface {}interface BazInterface {}class Barimplements BazInterface{}
publicfunction __construct(privateBarInterface$bar)// Type error, $bar must be of type BarInterface

Currently the above situation is allowed, and will ultimately lead to a type error at runtime when trying to injectBarInterface, becauseBar is not compatible. I think this situation should be raised as a configuration error, as I can't think of any valid use case for this.

I might be missing some use cases, and this might have been already discussed in some way, so any input appreciated, even if you think this is a bad idea for some reason 🙃
Thanks!

@carsonbot
Copy link

Hey!

To help keep things organized, we don't allow "Draft" pull requests. Could you please click the "ready for review" button or close this PR and open a new one when you are done?

Note that a pull request does not have to be "perfect" or "ready for merge" when you first open it. We just want it to be ready for a first review.

Cheers!

Carsonbot

@n-valverden-valverde marked this pull request as ready for reviewJune 22, 2023 15:48
@carsonbotcarsonbot added this to the6.4 milestoneJun 22, 2023
@carsonbot
Copy link

Hey!

I see that this is your first PR. That is great! Welcome!

Symfony has acontribution guide which I suggest you to read.

In short:

  • Always add tests
  • Keep backward compatibility (seehttps://symfony.com/bc).
  • Bug fixes must be submitted against the lowest maintained branch where they apply (seehttps://symfony.com/releases)
  • Features and deprecations must be submitted against the 6.4 branch.

Review the GitHub status checks of your pull request and try to solve the reported issues. If some tests are failing, try to see if they are failing because of this change.

When two Symfony core team members approve this change, it will be merged and you will become an official Symfony contributor!
If this PR is merged in a lower version branch, it will be merged up to all maintained branches within a few days.

I am going to sit back now and wait for the reviews.

Cheers!

Carsonbot

@n-valverden-valverdeforce-pushed thefeat/check-alias-validity-pass branch 2 times, most recently from41b5f63 to810f7e9CompareJune 23, 2023 08:51
@n-valverde
Copy link
ContributorAuthor

Few more thoughts for people coming here:

  • There is thelint:container command which could be useful, but I think does not match exactly this use case. As far as I understand it, it only checks type compatibility of arguments, so that leaves the possibility of defining a bad service from a lib developer side, and the issue will only be spotted by end user when trying to inject the badly configured service (Which is why I came here: api-platform/core:^2.7 is severely affected by this, and runninglint:container does not spot the issue)
  • I am also thinking that adding a flag like--all to thelint:container command, to make theCheckTypeDeclarationPass run before removals could be a good addition, any thought on this?
  • I understand that this proposal could be a dead end, with autoload, performance concern, or whatever, so maybe that could just be added to thelint:container checks
  • Failing tests are due to reflection going through thetrigger_deprecation calls, and same happens if autoload triggers, so I'm not sure there is any way to deal with that

Friendly ping@nicolas-grekas since you've worked on the initiallint:container command 😇

@nicolas-grekas
Copy link
Member

For sure this shouldn't be part of the always-on passes but if adding this tolint:container helps, why not.

n-valverde reacted with thumbs up emoji

@nicolas-grekasnicolas-grekas modified the milestones:6.4,7.1Nov 15, 2023
@fabpot
Copy link
Member

@n-valverde Can you work on the change suggested by@nicolas-grekas

@n-valverden-valverdeforce-pushed thefeat/check-alias-validity-pass branch 2 times, most recently fromee18b9c to4aebb69CompareFebruary 4, 2024 11:11
@n-valverde
Copy link
ContributorAuthor

Hello, sorry for the delay, I rebased on 7.1 and made the change so the pass is only applied tolint:container but I have additional questions/concerns:

  • I have to register this pass before removals, that makes sense for me because of the situation described above, but I'm not sure if this could trigger false positives
  • Was about to update the changelog, but I am wondering if this pass should remain in the DependencyInjection component since it is only used by thelint:container from FrameworkBundle (but it is the same forCheckTypeDeclarationsPass)

@fabpot
Copy link
Member

Hello, sorry for the delay, I rebased on 7.1 and made the change so the pass is only applied tolint:container but I have additional questions/concerns:

* I have to register this pass before removals, that makes sense for me because of the situation described above, but I'm not sure if this could trigger false positives* Was about to update the changelog, but I am wondering if this pass should remain in the DependencyInjection component since it is only used by the `lint:container` from FrameworkBundle (but it is the same for `CheckTypeDeclarationsPass`)

That makes sense to me as it allows developers not using the full stack framework to still use the pass.

n-valverde reacted with thumbs up emoji

@fabpotfabpotforce-pushed thefeat/check-alias-validity-pass branch fromd598f13 toc5dff26CompareFebruary 6, 2024 17:51
@fabpot
Copy link
Member

Thank you@n-valverde.

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@fabpotfabpotfabpot approved these changes

Assignees

No one assigned

Projects

None yet

Milestone

7.1

Development

Successfully merging this pull request may close these issues.

4 participants

@n-valverde@carsonbot@nicolas-grekas@fabpot

[8]ページ先頭

©2009-2025 Movatter.jp