Fix ISB001 misfires on proxy fields that are disposed#428
Fix ISB001 misfires on proxy fields that are disposed#428
Conversation
…gned to a field When GetProxyAsync or new ServiceBrokerClient is inside a lambda that is assigned to a field (e.g., AsyncLazy<ServiceBrokerClient>), FindAncestors incorrectly crossed the anonymous function boundary and attributed the proxy to the outer field. This caused ISB001 to require disposal of a field that doesn't directly hold a proxy. The fix prevents EnsureAssignedValueIsDisposed from crossing anonymous function (lambda) or local function boundaries when looking for ancestor assignments. Co-authored-by: AArnott <3548+AArnott@users.noreply.github.com>
Co-authored-by: AArnott <3548+AArnott@users.noreply.github.com>
|
@copilot Where did this lambdas handling change come from? The issue you were supposed to fix mentioned nothing about lambdas. It was about Dispose methods that were Please start from scratch and focus on the problem identified by the issue. |
…isons Replace ImmutableArray<T>.Contains() calls (which use default reference equality) with SymbolEqualityComparer.Default.Equals() for three critical symbol comparisons: 1. AllInterfaces.Contains(idisposable) - controls whether Dispose methods are analyzed for the type (affects override Dispose(bool) recognition) 2. getProxyAsyncMethods.Contains(...) - identifies GetProxyAsync calls 3. ExplicitInterfaceImplementations.Contains(disposeMethod) - recognizes explicit IDisposable.Dispose() implementations Also adds two new tests for override Dispose(bool) with base class and explicit interface IDisposable.Dispose() with cast-based disposal. Co-authored-by: AArnott <3548+AArnott@users.noreply.github.com>
Reverted the lambda changes and started from scratch. The root cause is that three
Fixed all three to use Warning Firewall rules blocked me from connecting to one or more addresses (expand for details)I tried to connect to the following addresses, but was blocked by firewall rules:
If you need me to access, download, or install something from one of these locations, you can either:
|
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
ISB001 false-positives when proxy fields are properly disposed in
override Dispose(bool)methods or explicitIDisposable.Dispose()implementations.The root cause is that three
ImmutableArray<T>.Contains()calls used default reference equality instead ofSymbolEqualityComparerto compare Roslyn symbols, which can fail to match symbols in complex compilation environments (e.g., VS extensions with many assembly references):AllInterfaces.Contains(idisposable)— controls whether Dispose methods are analyzed for the type. If this comparison fails,AnalyzeDisposeMethodsis never registered, so no Dispose method (includingoverride Dispose(bool)) is analyzed.getProxyAsyncMethods.Contains(...)— identifiesGetProxyAsynccalls.ExplicitInterfaceImplementations.Contains(disposeMethod)— recognizes explicitIDisposable.Dispose()implementations.Changes
AllInterfaces.Contains(idisposable)→AllInterfaces.Any(i => SymbolEqualityComparer.Default.Equals(i, idisposable))— ensures Dispose method analysis is registered even whenIDisposableis inherited from a base typegetProxyAsyncMethods.Contains(...)→ usesSymbolEqualityComparer.Default.Equals()— consistent symbol comparison forGetProxyAsyncidentificationExplicitInterfaceImplementations.Contains(disposeMethod)→ usesSymbolEqualityComparer.Default.Equals()— ensures explicitIDisposable.Dispose()implementations are recognizedoverride Dispose(bool)with base class providingIDisposable, and explicitIDisposable.Dispose()with cast-based disposal patternOriginal prompt
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.