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 lost diagnostics #52715

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

bernd5
Copy link
Contributor

@bernd5 bernd5 commented Apr 18, 2021

fixes: #52714

@bernd5 bernd5 marked this pull request as ready for review April 18, 2021 15:38
@bernd5 bernd5 requested a review from a team as a code owner April 18, 2021 15:38
@cston
Copy link
Member

cston commented Apr 18, 2021

Please include a test for the scenario being addressed. For a pattern test, perhaps add to PatternMatchingTests3.

@@ -1035,7 +1035,7 @@ private void EnforceDoesNotReturn(SyntaxNode? syntaxOpt)
// Once we address https://github.com/dotnet/roslyn/issues/46579 we should also always pass `getFinalNullableState: true` in debug mode.
// We will likely always need to write a 'null' out for the out parameter in this code path, though, because
// we don't want to introduce behavior differences between debug and release builds
Analyze(compilation, method, node, new DiagnosticBag(), useConstructorExitWarnings: false, initialNullableState: null, getFinalNullableState: false, out _, requiresAnalysis: false);
Analyze(compilation, method, node, diagnostics, useConstructorExitWarnings: false, initialNullableState: null, getFinalNullableState: false, out _, requiresAnalysis: false);
Copy link
Member

Choose a reason for hiding this comment

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

The call to Analyze() here is only used to test nullable analysis, not for reporting diagnostics. (IsNullableAnalysisEnabledAlways is usually false in RELEASE builds.) The diagnostics here should be dropped.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

As mentioned in #52714 one side effect of this analyze call is that it sees that null is not handled in a switch expression. And a diagnostic is emitted for that.
Perhaps that check should be moved somewhere else?
I encountered that while I wrote a test for switch-expression "IsExhaustive".

But your are right that this change alone is insufficient because the warning I'm looking for is filtered out in CSharpDiagnosticFilter.GetDiagnosticReport

            nullableWarnings.Add(GetId(ErrorCode.WRN_SwitchExpressionNotExhaustiveForNull));
            nullableWarnings.Add(GetId(ErrorCode.WRN_SwitchExpressionNotExhaustiveForNullWithWhen));
Debug.Assert(ErrorFacts.NullableWarnings.Contains(MessageProvider.Instance.GetIdForErrorCode((int)errorCode)));

This reverts commit 04ffc99.
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.

Missing warning for non-exhaustive switch-expression
2 participants