Skip to content
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

Allow omitting unused parameters #2180

Open
bartdesmet opened this issue Jan 28, 2019 · 5 comments
Open

Allow omitting unused parameters #2180

bartdesmet opened this issue Jan 28, 2019 · 5 comments
Milestone

Comments

@bartdesmet
Copy link

bartdesmet commented Jan 28, 2019

Referring to the discussion over at the Roslyn repo (dotnet/roslyn#32851), the IDE0060 warning can be raised for unused parameters that are required to match a delegate signature. There's currently no way to indicate the intent to ignore the parameter altogether, so suggestions are to remove the parameter (not always possible), or to put a suppression in place.

It'd be nice to have a way to indicate that a parameter is required but is being ignored explicitly. The closest existing language feature seems to be the discard _, but it suffers from being a valid identifier already. Another option would be to follow C++'s lead to allow omitting a name altogether:

void MyHandler1(object _, BarEventArgs e) => Console.WriteLine(e.Foo);
void MyHandler2(object, BarEventArgs e) => Console.WriteLine(e.Foo);

Note that IDE0060 has special cases for typical event signatures, to avoid raising warnings for these. Nonetheless, there are many places where having a parameter is imposed, and there's no way to indicate not caring about it explicitly. E.g. method group conversion for delegates and events, interface implementation, overriding base members, etc.

The idea would be: if a parameter name was written down, you better use it (if not, IDE0060 results). If you explicitly don't want to use it, you can use some way to discard it (and IDE0060 can offer a code fix that performs the edit).

Design Meetings

@mavasani
Copy link

Tagging @jcouv

@alrz
Copy link
Contributor

alrz commented Jan 28, 2019

I think permitting multiple underscores (discard) as parameter names for methods would have the same effect. For now, it is planned to permit that only for lambda parameters.

@jcouv
Copy link
Member

jcouv commented Jan 28, 2019

Relates to #111 ("Discard for lambda parameters (_, _) =>").

@jcouv
Copy link
Member

jcouv commented Oct 12, 2020

Tagging @CyrusNajmabadi in case he wants to champion this

@CyrusNajmabadi
Copy link
Member

I will champion this.

@jcouv jcouv added this to the 10.0 candidate milestone Oct 14, 2020
@333fred 333fred modified the milestones: 10.0 candidate, 10.0 Working Set Oct 14, 2020
@CyrusNajmabadi CyrusNajmabadi removed their assignment Sep 26, 2022
@333fred 333fred modified the milestones: Working Set, Backlog Sep 26, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants