@@ -58,13 +58,24 @@ private static void HandleFieldOrProperty(SyntaxNodeAnalysisContext context, Fie
5858 {
5959 context . ReportDiagnostic ( Diagnostic . Create ( Descriptors . IDISP008DoNotMixInjectedAndCreatedForMember , context . Node . GetLocation ( ) ) ) ;
6060 }
61- else if ( DisposableMember . IsDisposed ( member , context . SemanticModel , context . CancellationToken ) . IsEither ( Result . No , Result . AssumeNo ) &&
62- ! TestFixture . IsAssignedInInitializeAndDisposedInCleanup ( member , context . SemanticModel , context . CancellationToken ) )
61+ else if ( TestFixture . IsAssignedInInitialize ( member , context . SemanticModel , context . CancellationToken , out _ , out var setupAttribute ) )
62+ {
63+ if ( ! DisposedInTearDown ( ) )
64+ {
65+ context . ReportDiagnostic ( Diagnostic . Create ( Descriptors . IDISP002DisposeMember , context . Node . GetLocation ( ) ) ) ;
66+ }
67+
68+ bool DisposedInTearDown ( )
69+ {
70+ return TestFixture . FindTearDown ( setupAttribute ! , context . SemanticModel , context . CancellationToken ) is { } tearDown &&
71+ DisposableMember . IsDisposed ( member . FieldOrProperty , tearDown , context . SemanticModel , context . CancellationToken ) ;
72+ }
73+ }
74+ else if ( DisposableMember . IsDisposed ( member , context . SemanticModel , context . CancellationToken ) . IsEither ( Result . No , Result . AssumeNo ) )
6375 {
6476 context . ReportDiagnostic ( Diagnostic . Create ( Descriptors . IDISP002DisposeMember , context . Node . GetLocation ( ) ) ) ;
6577
66- if ( ! TestFixture . IsAssignedInInitialize ( member , context . SemanticModel , context . CancellationToken , out _ , out _ ) &&
67- DisposeMethod . FindFirst ( member . FieldOrProperty . ContainingType , context . Compilation , Search . TopLevel ) is null )
78+ if ( DisposeMethod . FindFirst ( member . FieldOrProperty . ContainingType , context . Compilation , Search . TopLevel ) is null )
6879 {
6980 context . ReportDiagnostic ( Diagnostic . Create ( Descriptors . IDISP006ImplementIDisposable , member . Declaration . GetLocation ( ) ) ) ;
7081 }
0 commit comments