Skip to content

Commit

Permalink
feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
MartyIX committed Nov 3, 2023
1 parent 2975f53 commit e3c71e4
Show file tree
Hide file tree
Showing 2 changed files with 122 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3668,6 +3668,7 @@ public ValueTask DisposeAsync()
}
}
// No diagnostic for DisposeCoreAsync.
class B : IAsyncDisposable
{
private readonly object disposedValueLock = new object();
Expand All @@ -3681,30 +3682,142 @@ public B()
protected virtual async ValueTask DisposeCoreAsync()
{
lock (this.disposedValueLock)
lock (disposedValueLock)
{
if (this.disposedValue)
if (disposedValue)
{
return;
}
this.disposedValue = true;
disposedValue = true;
}
await a.DisposeAsync().ConfigureAwait(false);
}
public async ValueTask DisposeAsync()
{
await this.DisposeCoreAsync().ConfigureAwait(false);
await DisposeCoreAsync().ConfigureAwait(false);
GC.SuppressFinalize(this);
}
}
// No diagnostic for DisposeAsyncCore.
class C : IAsyncDisposable
{
private readonly object disposedValueLock = new object();
private bool disposedValue;
private readonly A a;
public C()
{
a = new A();
}
protected virtual async ValueTask DisposeAsyncCore()
{
lock (disposedValueLock)
{
if (disposedValue)
{
return;
}
disposedValue = true;
}
await a.DisposeAsync().ConfigureAwait(false);
}
public async ValueTask DisposeAsync()
{
await DisposeAsyncCore().ConfigureAwait(false);
GC.SuppressFinalize(this);
}
}
"
}.RunAsync();

// How to fix: "error BC36945: The 'Async' modifier can only be used on Subs, or on Functions that return Task or Task(Of T)."?
/*
TODO: VB test.
await new VerifyVB.Test
{
ReferenceAssemblies = AdditionalMetadataReferences.DefaultWithAsyncInterfaces,
TestCode = @"
Imports System
Imports System.Threading.Tasks
Class A
Implements IAsyncDisposable
Public Function DisposeAsync() As ValueTask Implements IAsyncDisposable.DisposeAsync
Return Nothing
End Function
End Class
' No diagnostic for DisposeCoreAsync.
Class B
Implements IAsyncDisposable
Private ReadOnly disposedValueLock As Object = New Object()
Private disposedValue As Boolean
Private ReadOnly a As A
Public Sub New()
a = New A()
End Sub
Protected Overridable Async Function DisposeCoreAsync() As ValueTask
SyncLock disposedValueLock
If disposedValue Then
Return
End If
disposedValue = True
End SyncLock
Await a.DisposeAsync().ConfigureAwait(False)
End Function
Public Async Function DisposeAsync() As ValueTask Implements IAsyncDisposable.DisposeAsync
Await DisposeCoreAsync.ConfigureAwait(false)
GC.SuppressFinalize(Me)
End Function
End Class
' No diagnostic for DisposeAsyncCore.
Class C
Implements IAsyncDisposable
Private ReadOnly disposedValueLock As Object = New Object()
Private disposedValue As Boolean
Private ReadOnly a As A
Public Sub New()
a = New A()
End Sub
Protected Overridable Async Function DisposeAsyncCore() As ValueTask
SyncLock disposedValueLock
If disposedValue Then
Return
End If
disposedValue = True
End SyncLock
Await a.DisposeAsync().ConfigureAwait(False)
End Function
Public Function DisposeAsync() As ValueTask Implements IAsyncDisposable.DisposeAsync
Await DisposeAsyncCore.ConfigureAwait(false)
GC.SuppressFinalize(Me)
End Function
End Class"
}.RunAsync();
*/
}

Expand Down
8 changes: 4 additions & 4 deletions src/Utilities/Compiler/Extensions/IMethodSymbolExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -288,11 +288,11 @@ private static bool HasDisposeAsyncMethodSignature(this IMethodSymbol method,
}

/// <summary>
/// Checks if the given method has the signature "override Task DisposeCoreAsync(bool)".
/// Checks if the given method has the signature "override Task DisposeCoreAsync(bool)" or "override Task DisposeAsyncCore(bool)".
/// </summary>
private static bool HasOverriddenDisposeCoreAsyncMethodSignature(this IMethodSymbol method, [NotNullWhen(returnValue: true)] INamedTypeSymbol? task)
{
return method.Name == "DisposeCoreAsync" &&
return (method.Name == "DisposeCoreAsync" || method.Name == "DisposeAsyncCore") &&
method.MethodKind == MethodKind.Ordinary &&
method.IsOverride &&
SymbolEqualityComparer.Default.Equals(method.ReturnType, task) &&
Expand All @@ -301,11 +301,11 @@ private static bool HasOverriddenDisposeCoreAsyncMethodSignature(this IMethodSym
}

/// <summary>
/// Checks if the given method has the signature "virtual ValueTask DisposeCoreAsync()".
/// Checks if the given method has the signature "virtual ValueTask DisposeCoreAsync()" or "virtual ValueTask DisposeAsyncCore()".
/// </summary>
private static bool HasVirtualDisposeCoreAsyncMethodSignature(this IMethodSymbol method, [NotNullWhen(returnValue: true)] INamedTypeSymbol? valueTask)
{
return method.Name == "DisposeCoreAsync" &&
return (method.Name == "DisposeCoreAsync" || method.Name == "DisposeAsyncCore") &&
method.MethodKind == MethodKind.Ordinary &&
method.IsVirtual &&
SymbolEqualityComparer.Default.Equals(method.ReturnType, valueTask) &&
Expand Down

0 comments on commit e3c71e4

Please sign in to comment.