Skip to content

Commit 82a2229

Browse files
committed
IDISP003 when discarding.
Was not really a bug but there are clearer warnings we can produce. Nicer when suppressing if nothing else. Fix #206
1 parent 3b13610 commit 82a2229

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

IDisposableAnalyzers.Test/IDISP003DisposeBeforeReassigningTests/Valid.cs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1688,5 +1688,27 @@ public void Dispose()
16881688

16891689
RoslynAssert.Valid(Analyzer, DisposableCode, baseClass, code);
16901690
}
1691+
1692+
[Test]
1693+
public static void DiscardedTwice()
1694+
{
1695+
var code = @"
1696+
namespace N
1697+
{
1698+
using System;
1699+
using System.IO;
1700+
1701+
public class C
1702+
{
1703+
public void M()
1704+
{
1705+
_ = File.OpenRead(string.Empty);
1706+
_ = File.OpenRead(string.Empty);
1707+
}
1708+
}
1709+
}";
1710+
1711+
RoslynAssert.Valid(Analyzer, code);
1712+
}
16911713
}
16921714
}

IDisposableAnalyzers/Analyzers/AssignmentAnalyzer.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,8 @@ private static bool IsReassignedWithCreated(AssignmentExpressionSyntax assignmen
6868
}
6969

7070
if (assignedSymbol == KnownSymbol.SerialDisposable.Disposable ||
71-
assignedSymbol == KnownSymbol.SingleAssignmentDisposable.Disposable)
71+
assignedSymbol == KnownSymbol.SingleAssignmentDisposable.Disposable ||
72+
assignedSymbol is IDiscardSymbol)
7273
{
7374
return false;
7475
}

0 commit comments

Comments
 (0)