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

Only the compiler analyzer can use CS or BC prefix for diagnostics #23776

Merged
merged 3 commits into from
Dec 14, 2017

Conversation

jcouv
Copy link
Member

@jcouv jcouv commented Dec 14, 2017

Customer scenario

Some analyzer (such as the UnboundIdentifier analyzer in the linked issue) produce similar diagnostics (ID and message) to the compiler's.
That is extremely confusing and leads to wasting time in investigation.

In the screenshot below, the red squiggles on nameof are actually produced by an analyzer, which makes a "CS0107" diagnostic...
image

Bugs this fixes

Fixes part of #23667
Fixes part of #22615

Workarounds, if any

Not applicable.

Risk

Low. This PR modifies the analyzer infrastructure to catch when non-compiler analyzers produce a diagnostic starting with "CS" or "BC". A couple of such faulty analyzers are updated to produce distinct diagnostics instead (with correct "IDE" prefix).

Performance impact

Low. Just an additional validation on diagnostics.

Is this a regression from a previous update?

No.

How was the bug found?

Some customer reported issues caused me to hit this problem during investigation.

@jcouv jcouv added Area-IDE PR For Personal Review Only The PR doesn’t require anyone other than the developer to review it. labels Dec 14, 2017
@jcouv jcouv added this to the 15.6 milestone Dec 14, 2017
@jcouv jcouv self-assigned this Dec 14, 2017
@jcouv jcouv requested a review from a team as a code owner December 14, 2017 00:36
@jcouv jcouv force-pushed the nameof-bug branch 2 times, most recently from e1a8d9d to bc5462f Compare December 14, 2017 19:23
@jcouv jcouv removed the PR For Personal Review Only The PR doesn’t require anyone other than the developer to review it. label Dec 14, 2017
private static bool IsCompilerReservedDiagnostic(string id)
{
// Only the compiler analyzer should produce diagnostics with CS or BC prefixes (followed by digit)
if (id.Length >= 3 && (id.StartsWith("CS", StringComparison.Ordinal) || id.StartsWith("BC", StringComparison.Ordinal)))
Copy link
Contributor

Choose a reason for hiding this comment

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

Would it be better to instead check for presence of custom tag WellKnownDiagnosticTags.Compiler on the diagnostic descriptor?

Copy link
Member Author

Choose a reason for hiding this comment

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

It feels like this tag would only be set by the compiler, and so would not help catch regular analyzers misbehaving.
I can double-check though.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah yes, that is correct. We should probably add to your current check and disallow that tag on any analyzer diagnostic. Only compiler diagnostics should use that tag.

Copy link
Contributor

Choose a reason for hiding this comment

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

That doesn't need to happen in this PR though..

Copy link
Member Author

Choose a reason for hiding this comment

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

Confirmed (by stepping through the tests I added for this scenario) that tags are not a good criteria.

@jcouv
Copy link
Member Author

jcouv commented Dec 14, 2017

test windows_release_unit64_prtest please

@jcouv
Copy link
Member Author

jcouv commented Dec 14, 2017

@Pilchie for ask-mode approval for 15.6. Thanks

@jcouv jcouv merged commit 850f809 into dotnet:master Dec 14, 2017
@jcouv jcouv deleted the nameof-bug branch December 14, 2017 21:56
mavasani added a commit to mavasani/roslyn that referenced this pull request Jun 28, 2018
This PR reverts that change and a similar diagnostic will be implemented as an analyzer with dotnet/roslyn-analyzers#1727.

Fixes dotnet#25748
jinujoseph added a commit that referenced this pull request Jun 29, 2018
Revert compat break change made as part of #23776
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants