-
Notifications
You must be signed in to change notification settings - Fork 1k
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
Comments
This is a perfect example of what analyzers were designed for |
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 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. |
Summary
Compiler flag in
csproj
ExplicitDIM and NoDuplicateNameExplicitDIM to enforce that implementation of DIM must always be explicit
NoDuplicateName to bring back
CS0136
for non static local function and lambda expressionMotivation
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_
variableI 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 allowerror
warning
andnone
(orfalse
). I wish it should bewarning
by defaultThe text was updated successfully, but these errors were encountered: