Skip to content

Commit a08f86e

Browse files
committed
Workaround for #32100 in Dispose analyzer
Workaround for #32100 for Dev16.2
1 parent 9526111 commit a08f86e

2 files changed

Lines changed: 38 additions & 0 deletions

File tree

src/EditorFeatures/CSharpTest/DisposeAnalysis/DisposeObjectsBeforeLosingScopeTests.cs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5024,6 +5024,37 @@ void M1()
50245024
}");
50255025
}
50265026

5027+
[Fact, WorkItem(32100, "https://github.com/dotnet/roslyn/issues/32100")]
5028+
public async Task UsingDeclaration()
5029+
{
5030+
await TestDiagnosticsAsync(@"
5031+
using System;
5032+
class C : IDisposable
5033+
{
5034+
public void Dispose() { }
5035+
void M1()
5036+
{
5037+
[|using var c = new C()|];
5038+
}
5039+
}", parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.Preview));
5040+
}
5041+
5042+
[Fact, WorkItem(32100, "https://github.com/dotnet/roslyn/issues/32100")]
5043+
public async Task UsingDeclarationWithInitializer()
5044+
{
5045+
await TestDiagnosticsAsync(@"
5046+
using System;
5047+
class C : IDisposable
5048+
{
5049+
public int P { get; set; }
5050+
public void Dispose() { }
5051+
void M1()
5052+
{
5053+
[|using var c = new C() { P = 1 }|];
5054+
}
5055+
}", parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.Preview));
5056+
}
5057+
50275058
[Fact]
50285059
public async Task MissingDisposeInMethodWithAttributes()
50295060
{

src/Features/Core/Portable/DisposeAnalysis/DisposeObjectsBeforeLosingScopeDiagnosticAnalyzer.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,13 @@ private void PerformFlowAnalysisOnOperationBlock(
103103
ComputeDiagnostics(disposeDataAtExit, notDisposedDiagnostics, mayBeNotDisposedDiagnostics,
104104
disposeAnalysisResult, pointsToAnalysisResult);
105105

106+
if (disposeAnalysisResult.ControlFlowGraph.OriginalOperation.HasAnyOperationDescendant(o => o.Kind == OperationKind.None))
107+
{
108+
// Workaround for https://github.com/dotnet/roslyn/issues/32100
109+
// Bail out in presence of OperationKind.None - not implemented IOperation.
110+
return;
111+
}
112+
106113
// Report diagnostics preferring *not* disposed diagnostics over may be not disposed diagnostics
107114
// and avoiding duplicates.
108115
foreach (var diagnostic in notDisposedDiagnostics.Concat(mayBeNotDisposedDiagnostics))

0 commit comments

Comments
 (0)