Skip to content

Commit

Permalink
Avoid tail recursion in IsAsyncDisposeImplementation (#4432)
Browse files Browse the repository at this point in the history
Co-authored-by: Amaury Levé <amauryleve@microsoft.com>
  • Loading branch information
SimonCropp and Evangelink authored Dec 26, 2024
1 parent d109b63 commit 83f6a63
Showing 1 changed file with 16 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,20 +68,24 @@ public static bool IsDisposeImplementation([NotNullWhen(returnValue: true)] this
/// </summary>
public static bool IsAsyncDisposeImplementation([NotNullWhen(returnValue: true)] this IMethodSymbol? method, [NotNullWhen(returnValue: true)] INamedTypeSymbol? iAsyncDisposable, [NotNullWhen(returnValue: true)] INamedTypeSymbol? valueTaskType)
{
if (method == null)
while (true)
{
return false;
}
if (method == null)
{
return false;
}

if (method.IsOverride)
{
return method.OverriddenMethod.IsAsyncDisposeImplementation(iAsyncDisposable, valueTaskType);
}
if (method.IsOverride)
{
method = method.OverriddenMethod;
continue;
}

// Identify the implementor of IAsyncDisposable.Dispose in the given method's containing type and check
// if it is the given method.
return SymbolEqualityComparer.Default.Equals(method.ReturnType, valueTaskType) &&
method.Parameters.IsEmpty &&
method.IsImplementationOfInterfaceMethod(null, iAsyncDisposable, "DisposeAsync");
// Identify the implementor of IAsyncDisposable.Dispose in the given method's containing type and check
// if it is the given method.
return SymbolEqualityComparer.Default.Equals(method.ReturnType, valueTaskType) &&
method.Parameters.IsEmpty &&
method.IsImplementationOfInterfaceMethod(null, iAsyncDisposable, "DisposeAsync");
}
}
}

0 comments on commit 83f6a63

Please sign in to comment.