-
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
Fix error message when trying to use using-static with an invalid type #68571
Fix error message when trying to use using-static with an invalid type #68571
Conversation
@jcouv ptal |
@@ -7511,4 +7523,7 @@ To remove the warning, you can use /reference instead (set the Embed Interop Typ | |||
<data name="ERR_UnsupportedPrimaryConstructorParameterCapturingRefAny" xml:space="preserve"> | |||
<value>Cannot use primary constructor parameter of type '{0}' inside an instance member</value> | |||
</data> | |||
<data name="ERR_BadUsingStaticType" xml:space="preserve"> | |||
<value>'{0}' type is not valid for 'using static'. Only a class, struct, interface, enum, delegate or namespace can be used.</value> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Oxford comma is commonly used, I think. e.g:
<value>An object reference is required for the non-static field, method, or property '{0}'</value> - Most errors don't end with period.
<value>'{0}' type is not valid for 'using static'. Only a class, struct, interface, enum, delegate or namespace can be used.</value> | |
<value>'{0}' type is not valid for 'using static'. Only a class, struct, interface, enum, delegate, or namespace can be used</value> |
i see a massive amount of errors with ending periods. I'm fine keeping as is. My pref would be that if we care about ending periods we apply it to everything and are consistent everywhere. |
I changed the comma. I see both styles in the compiler, but it does look like a lot more use the oxford comma. |
// (5,18): error CS9137: 'pointer' type is not valid for 'using static'. Only a class, struct, interface, enum, delegate or namespace can be used. | ||
// using static A; | ||
Diagnostic(ErrorCode.ERR_BadUsingStaticType, "A").WithArguments("pointer").WithLocation(5, 18), | ||
// (5,18): error CS0214: Pointers and fixed size buffers may only be used in an unsafe context |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sure. let me see how possible that is.
// (5,18): error CS9137: 'function pointer' type is not valid for 'using static'. Only a class, struct, interface, enum, delegate or namespace can be used. | ||
// using static A; | ||
Diagnostic(ErrorCode.ERR_BadUsingStaticType, "A").WithArguments("function pointer").WithLocation(5, 18), | ||
// (5,18): error CS0214: Pointers and fixed size buffers may only be used in an unsafe context |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM (commit 3)
@dotnet/roslyn-compiler For the second review |
@Youssef1313 I agree, and for errors fitting the pattern we should strive to make all new messages consistent with the guidelines. Note that the exception to this case is an error with more than one sentence, where both will end with a period. This particular diagnostic fits the exception criteria (several others under nullable reference types do as well). |
Fixes #68546