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

Fix error message when trying to use using-static with an invalid type #68571

Merged
merged 5 commits into from
Jun 13, 2023

Conversation

CyrusNajmabadi
Copy link
Member

Fixes #68546

@CyrusNajmabadi CyrusNajmabadi requested a review from a team as a code owner June 13, 2023 03:34
@dotnet-issue-labeler dotnet-issue-labeler bot added Area-Compilers untriaged Issues and PRs which have not yet been triaged by a lead labels Jun 13, 2023
@CyrusNajmabadi
Copy link
Member Author

@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>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
<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>

@CyrusNajmabadi
Copy link
Member Author

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.

@CyrusNajmabadi
Copy link
Member Author

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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

// (5,18): error CS0214: Pointers and fixed size buffers may only be used in an unsafe context

Consider suppressing this error to reduce the noise.

Copy link
Member Author

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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

// (5,18): error CS0214: Pointers and fixed size buffers may only be used in an unsafe context

Here as well

Copy link
Contributor

@AlekseyTs AlekseyTs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM (commit 3)

@AlekseyTs
Copy link
Contributor

@dotnet/roslyn-compiler For the second review

@sharwell
Copy link
Member

Most errors don't end with period.

@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).

@CyrusNajmabadi CyrusNajmabadi enabled auto-merge (squash) June 13, 2023 19:10
@CyrusNajmabadi CyrusNajmabadi merged commit 2807574 into dotnet:main Jun 13, 2023
25 checks passed
@ghost ghost added this to the Next milestone Jun 13, 2023
@CyrusNajmabadi CyrusNajmabadi deleted the usingStaticMessage branch June 13, 2023 23:11
@RikkiGibson RikkiGibson modified the milestones: Next, 17.7 P3 Jun 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Compilers untriaged Issues and PRs which have not yet been triaged by a lead
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Incorrect error message on using static directive with alias to non-named type
6 participants