-
Notifications
You must be signed in to change notification settings - Fork 7
Open
Description
Suppose the following (taken from tests):
public partial class Stuff
{
[CreateSyncVersion]
static async Task<int> HalfCheckSumAsync(Memory<byte> buffer, Stream stream, CancellationToken ct)
=> (await ChecksumReadAsync(buffer, stream, ct).ConfigureAwait(false)) / 2;
[CreateSyncVersion]
static async Task<int> ChecksumReadAsync(Memory<byte> buffer, Stream stream, CancellationToken ct)
{
int bytesRead = await stream.ReadAsync(buffer, ct).ConfigureAwait(true);
return Checksum(buffer.Span.Slice(0, bytesRead));
}
static int Checksum(Span<byte> buffer) => 0;
}Suppose further that the developer wants to offer another overload of HalfCheckSumAsync without the ct parameter:
public partial class Stuff
{
[CreateSyncVersion]
static Task<int> HalfCheckSumAsync(Memory<byte> buffer, Stream stream) =>
HalfCheckSumAsync(buffer, stream, CancellationToken.None);
[CreateSyncVersion]
static async Task<int> HalfCheckSumAsync(Memory<byte> buffer, Stream stream, CancellationToken ct)
=> (await ChecksumReadAsync(buffer, stream, ct).ConfigureAwait(false)) / 2;
[CreateSyncVersion]
static async Task<int> ChecksumReadAsync(Memory<byte> buffer, Stream stream, CancellationToken ct)
{
int bytesRead = await stream.ReadAsync(buffer, ct).ConfigureAwait(true);
return Checksum(buffer.Span.Slice(0, bytesRead));
}
static int Checksum(Span<byte> buffer) => 0;
}Upon compilation, the following warning is emitted:
CSC : warning CS8785: Generator 'SyncMethodSourceGenerator' failed to generate source. It will not contribute to the output and compilation errors may occur as a result. Exception was of type 'ArgumentException' with message 'The hintName '.Stuff.HalfCheckSumAsync.g.cs' of the added source file must be unique within a generator. (Parameter 'hintName')'
You could say that the overload doesn't need [CreateSyncVersion] because it just delegates the implementation, but the generator should emit a diagnostic rather than crashing.
I also wonder what are you thoughts on overloads, whether those should be supported by-design or not.
Metadata
Metadata
Assignees
Labels
No labels