未验证 提交 4a877e62 编写于 作者: M Manish Vasani 提交者: GitHub

Merge pull request #46048 from mavasani/FixIDE0079

Fix KeyNotFound exception in RemoveUnnecessaryInlineSuppressionsDiagn…
......@@ -190,9 +190,12 @@ protected sealed override void InitializeWorker(AnalysisContext context)
// Remove entries for unhandled diagnostic ids.
foreach (var id in unhandledIds)
{
foreach (var (pragma, _) in idToPragmasMap[id])
if (idToPragmasMap.TryGetValue(id, out var pragmas))
{
pragmasToIsUsedMap.Remove(pragma);
foreach (var (pragma, _) in pragmas)
{
pragmasToIsUsedMap.Remove(pragma);
}
}
if (idToSuppressMessageAttributesMap.TryGetValue(id, out var attributeNodes))
......
......@@ -265,23 +265,34 @@ void M()
}
}
public enum TestKind
{
Pragmas,
SuppressMessageAttributes,
PragmasAndSuppressMessageAttributes
}
[Theory, CombinatorialData]
public async Task TestDoNotRemoveUnsupportedDiagnosticSuppression(bool disable)
[WorkItem(46047, "https://github.com/dotnet/roslyn/issues/46047")]
public async Task TestDoNotRemoveUnsupportedDiagnosticSuppression(bool disable, TestKind testKind)
{
var disableOrRestore = disable ? "disable" : "restore";
var pragmas = new StringBuilder();
var suppressMessageAttribtes = new StringBuilder();
foreach (var id in UnsupportedDiagnosticIds)
{
pragmas.AppendLine($@"#pragma warning {disableOrRestore} {id}");
suppressMessageAttribtes.AppendLine($@"[System.Diagnostics.CodeAnalysis.SuppressMessage(""Category"", ""{id}"")]");
if (testKind == TestKind.Pragmas || testKind == TestKind.PragmasAndSuppressMessageAttributes)
pragmas.AppendLine($@"#pragma warning {disableOrRestore} {id}");
if (testKind == TestKind.SuppressMessageAttributes || testKind == TestKind.PragmasAndSuppressMessageAttributes)
suppressMessageAttribtes.AppendLine($@"[System.Diagnostics.CodeAnalysis.SuppressMessage(""Category"", ""{id}"")]");
}
var source = $@"{{|FixAllInDocument:{pragmas}{suppressMessageAttribtes}|}}class Class {{ }}";
// Compiler diagnostics cannot be suppressed with SuppressMessageAttribute.
// Hence, attribute suppressions for compiler diagnostics are always unnecessary.
if (!IsCompilerDiagnosticsTest)
if (!IsCompilerDiagnosticsTest || testKind == TestKind.Pragmas)
{
await TestMissingInRegularAndScriptAsync(source);
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册