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

[Proposal]: Could we have compiler flag to disable or control DIM and duplicate scope naming? #3906

Closed
Thaina opened this issue Sep 18, 2020 · 4 comments

Comments

@Thaina
Copy link

Thaina commented Sep 18, 2020

Summary

Compiler flag in csproj ExplicitDIM and NoDuplicateName

ExplicitDIM to enforce that implementation of DIM must always be explicit
NoDuplicateName to bring back CS0136 for non static local function and lambda expression

Motivation

While C# 8 new feature is awesome and practically handy. There was also arguably dangerous and doubtful at the same time, especially DIM and scope naming of variable

While it cannot be retracted anymore and also I see the benefit of them, I wish I could have some control over their behaviour

As for DIM I wish I could enforce that its implementation must not be implicit. It would throw error on implicit implementation and so we could avoid unintentional overriding and diamond inheritance

As for scope naming. Only one scope naming I wish I should be override is the discard variable. I would like to avoid same name collision at any scope that the parent scope could be accessed. So I want to have CS0136 back for anything except discard _ variable

I think this should be possible to opt-in for each project so it should not break anything. And if possible I wish it could be default for C# 9 and could be opt-out just for C# 8 code or opt-out per file

NoDuplicateName could be allow error warning and none (or false). I wish it should be warning by default

@YairHalberstadt
Copy link
Contributor

This is a perfect example of what analyzers were designed for

@333fred
Copy link
Member

333fred commented Sep 18, 2020

Thanks for submitting this proposal. Unfortunately, the team does not feel that this proposal is in line with the current or future direction of the C# language. As such we are closing it. Compiler switches create dialects of the language, something we are very hesitant to do. Additionally, as Yair points out, this is exactly the type of thing that analyzers were designed to enable. If you feel strongly about this, I'd suggest taking that approach instead.

@333fred 333fred closed this as completed Sep 18, 2020
@Thaina
Copy link
Author

Thaina commented Sep 19, 2020

@333fred Is it possible at least as a flag for warning?

@333fred
Copy link
Member

333fred commented Sep 19, 2020

@333fred Is it possible at least as a flag for warning?

No. This is exactly the scenario analyzers are made for. We are not going to introduce a compiler flag to add a warning for blanket use of a feature that we just shipped. If you want to control feature usage, please use the existing infrastructure for controlling this.

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

3 participants