Skip to content

Commit babe4f8

Browse files
committed
IDISP009 don't warnd for ref struct
fix #432
1 parent 528287c commit babe4f8

2 files changed

Lines changed: 18 additions & 2 deletions

File tree

IDisposableAnalyzers.Test/IDISP009IsIDisposableTests/Valid.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -482,5 +482,21 @@ public interface IC
482482

483483
RoslynAssert.Valid(Analyzer, code);
484484
}
485+
486+
[Test]
487+
public static void RefStruct()
488+
{
489+
var code = """
490+
491+
namespace N;
492+
493+
public ref struct S
494+
{
495+
public void Dispose() { }
496+
}
497+
""";
498+
499+
RoslynAssert.Valid(Analyzer, code);
500+
}
485501
}
486502
}

IDisposableAnalyzers/Analyzers/DisposeMethodAnalyzer.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,13 @@ public override void Initialize(AnalysisContext context)
3232
private static void Handle(SyntaxNodeAnalysisContext context)
3333
{
3434
if (!context.IsExcludedFromAnalysis() &&
35-
context.ContainingSymbol is IMethodSymbol { IsStatic: false, ReturnsVoid: true, Name: "Dispose" } method &&
36-
context.Node is MethodDeclarationSyntax methodDeclaration)
35+
context is { ContainingSymbol: IMethodSymbol { IsStatic: false, ReturnsVoid: true, Name: "Dispose" } method, Node: MethodDeclarationSyntax methodDeclaration })
3736
{
3837
if (method is { DeclaredAccessibility: Accessibility.Public, Parameters.Length: 0 } &&
3938
method.GetAttributes().Length == 0)
4039
{
4140
if (!method.ExplicitInterfaceImplementations.Any() &&
41+
method.ContainingType is { IsRefLikeType: false } &&
4242
!IsInterfaceImplementation(method))
4343
{
4444
context.ReportDiagnostic(Diagnostic.Create(Descriptors.IDISP009IsIDisposable, methodDeclaration.Identifier.GetLocation()));

0 commit comments

Comments
 (0)