-
Notifications
You must be signed in to change notification settings - Fork 4.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
Compiler or analyzer should warn for lower-cased type names #56653
Comments
If this is about the language and our ability to add such types in a more confident manner, then i think this should be part of the compiler proper. That way every gets it, and everyone sees that this is the official guidance from the team on what you should/shouldn't do. |
Just realized, one issue we'll have to figure out is how we define "lower-case". |
All(char.IsLower)? |
Agree with @CyrusNajmabadi that the ideal here is for the compiler to emit a new warning as part of warning wave 7. If that cannot happen then we can consider shipping it as an analyzer. Considering that this is a fundamental part of C# it would seem to be appropriate for the dotnet/roslyn repo since dotnet/roslyn-analyzers is for warnings about .NET libraries instead of core language concepts. |
@jaredpar Should we contemplate doing this as part of warning wave 6 (ie. in .NET 6)? |
Will prefixing with Otherwise, I can't think of a good workaround, for example, for Xamarin's |
From discussion with Jared, it's too late for .NET 6. We could make this any early preview for release after that (such as 17.1). @Youssef1313 That's an excellent suggestion. It would make sense given that the |
Design Meeting Notes:
Proposal: Keep IDE analyzers as they are. The compiler will add a diagnostic behind a warning wave for VS 17.1 Preview 1. |
FYI, the proposal was discussed and refined in LDM 10/13/2021. Notes upcoming |
Hello there, In Unity, we are using lower-case names for some special types that we consider as "primitives" (e.g float4) So we have 2 questions:
|
Yes, as a warning, you can generally disable it for your entire compile.
Yes, it would likely apply downstream.
This would likely not be an issue. We would be looking for 'all lower cast ascii identifiers'. e.g. things like |
Thanks for the response @CyrusNajmabadi, sorry I cross posted (thought I deleted this one above) |
@soc Both alias C# keywords (e.g. class abc { } // warning |
@Youssef1313 The point is consistency: Do not make up rules for language users that you, as a language developer, don't intend to follow. |
I'm not really sure what you mean. |
I think they mean that if users aren't allowed to define a type that is all lowercase, then the runtime/language shouldn't either. |
If that's what @soc meant, then there are two things:
|
The point is exactly to have that block. We want the language to be able to use these keywords without colliding with anything a user does. If we continue to use the same space of names (like today), then nothing will change and we will have the same potential collision problem. |
|
Users can define types that could conflict with keywords we want to use in the language in the future. We want to explicitly steer people away from that. The entire point is to bifurcate the space of identifiers to ones we can safely use in the language without worry about conflit, and those that anyone can use themselves in their code. The point is to have a split. |
@CyrusNajmabadi Agreed. Not sure what you are arguing against? |
You said to Youssef1313:
I am arguing against that idea. The point is exactly to make up rules for users that the language itself won't follow. We are trying to split this space entirely so that we can have more names like |
Perhaps this issue and the discussion notes are misleading, because it's simply not "warn for lower-cased type names" then. |
It is warn for lower-cased type names. So |
And #56905 It is exactly that. :) |
So when compiling the BCL we'll get warnings for |
No. The bcl does not define those. So there's nothing to warn on. |
I think there might be a bit of confusion: |
@CyrusNajmabadi Then "warn for lower-cased type names, except our own" or "warn for lower-cased type names, except for type keywords" would be correct, but the title as given is misleading. |
@333fred I'm not confused thank you. |
There is really no exception. |
@Youssef1313 If you discuss type names then the "type-ness" of "type keywords" is more relevant that their "keyword-ness". |
Those are not type-names. They are built in keywords. We're not warning on keywords here, only type names. Thanks :)
The title is accurate (as is the linked issue). You're welcome to ask for clarity if the terminology isn't something you're totally familiar with of course. In this case though your point you raised isn't valid: "Do not make up rules for language users that you, as a language developer, don't intend to follow." We do you define type names in the language. That comes externally. We do define keywords, and we want to increase the likelihood that our keywords will not collide with user type names.
I'm not sure what point you're trying to make here. We're warning on lowercase type names because that's the space that we want to reserve for us for keywords (type or otherwise). |
This comment was marked as off-topic.
This comment was marked as off-topic.
@soc the relevance is the 'keyword-ness'. We want to be able to make keywords that do not collide with user types. It has nothing to do with the keyword being type-like (like ** Other examples are things like |
If you or anyone else wants to disallow using language keywords like these in your own projects, you can enable this style rule and make it a warning or error, as you see fit: https://docs.microsoft.com/en-us/dotnet/fundamentals/code-analysis/style-rules/ide0049 |
During LDM discussion on records, there was interest to have an analyzer warn on lower-cased type names. The motivation is that knowing that we discourage lower-cased type names would allow us to introduce new keywords (like
record
) with less concern about the breaking change.I'm not sure whether this should be done by the compiler, a roslyn analyzer or some BCL analyzer.
Design:
char.IsLower(...)
for lower-case check.@
prefix avoids warning.FYI @mikadumont @jmarolf
The text was updated successfully, but these errors were encountered: