@@ -52,12 +52,14 @@ static bool TryGetScope(SyntaxNode node, out BlockSyntax result)
5252 result = lambdaBody ;
5353 return true ;
5454 }
55- else if ( node . FirstAncestor < AccessorDeclarationSyntax > ( ) is { Body : BlockSyntax accessorBody } )
55+
56+ if ( node . FirstAncestor < AccessorDeclarationSyntax > ( ) is { Body : BlockSyntax accessorBody } )
5657 {
5758 result = accessorBody ;
5859 return true ;
5960 }
60- else if ( node . FirstAncestor < BaseMethodDeclarationSyntax > ( ) is { Body : BlockSyntax methodBody } )
61+
62+ if ( node . FirstAncestor < BaseMethodDeclarationSyntax > ( ) is { Body : BlockSyntax methodBody } )
6163 {
6264 result = methodBody ;
6365 return true ;
@@ -69,16 +71,17 @@ static bool TryGetScope(SyntaxNode node, out BlockSyntax result)
6971
7072 bool IsReassignedAfter ( SyntaxNode scope , InvocationExpressionSyntax disposeCall )
7173 {
72- using ( var walker = MutationWalker . Borrow ( scope , SearchScope . Member , semanticModel , cancellationToken ) )
74+ using var walker = AssignmentWalker . Borrow ( scope ) ;
75+ foreach ( var assignment in walker . Assignments )
7376 {
74- foreach ( var mutation in walker . All ( ) )
77+ if ( assignment . TryFirstAncestor ( out StatementSyntax ? statement ) &&
78+ disposeCall . IsExecutedBefore ( statement ) == ExecutedBefore . Yes &&
79+ statement . IsExecutedBefore ( expression ) == ExecutedBefore . Yes &&
80+ semanticModel . TryGetSymbol ( assignment . Left , cancellationToken , out var assigned ) &&
81+ Equals ( assigned , symbol ) &&
82+ IsCreation ( assignment . Right , semanticModel , cancellationToken ) . IsEither ( Result . Yes , Result . AssumeYes ) )
7583 {
76- if ( mutation . TryFirstAncestor ( out StatementSyntax ? statement ) &&
77- disposeCall . IsExecutedBefore ( statement ) == ExecutedBefore . Yes &&
78- statement . IsExecutedBefore ( expression ) == ExecutedBefore . Yes )
79- {
80- return true ;
81- }
84+ return true ;
8285 }
8386 }
8487
0 commit comments