zompinc/sync-method-generator

Generate code for classes with same name but different arity

Closed this issue · 2 comments

When I try to generate synchronous methods for classes with same name but different arity the generator fails.

Example: Serializer and Serialize<T>.

Generator '<redacted>' 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 '<redacted>.SerializeAsync.g.cs' of the added source file must be unique within a generator. (Parameter 'hintName')'.
System.ArgumentException: The hintName '<redacted>.SerializeAsync.g.cs' of the added source file must be unique within a generator. (Parameter 'hintName')
at Microsoft.CodeAnalysis.AdditionalSourcesCollection.Add(String hintName, SourceText source) in Z:\BuildAgent\work\3b7ce003563d6f8f\src\Compilers\Core\Portable\SourceGeneration\AdditionalSourcesCollection.cs:line 78
at Microsoft.CodeAnalysis.SourceOutputNode`1.AppendOutputs(IncrementalExecutionContext context, CancellationToken cancellationToken) in Z:\BuildAgent\work\3b7ce003563d6f8f\src\Compilers\Core\Portable\SourceGeneration\Nodes\SourceOutputNode.cs:line 111
-----


System.ArgumentException: The hintName '<redacted>.SerializeAsync.g.cs' of the added source file must be unique within a generator. (Parameter 'hintName')
at Microsoft.CodeAnalysis.AdditionalSourcesCollection.Add(String hintName, SourceText source) in Z:\BuildAgent\work\3b7ce003563d6f8f\src\Compilers\Core\Portable\SourceGeneration\AdditionalSourcesCollection.cs:line 78
at Microsoft.CodeAnalysis.SourceOutputNode`1.AppendOutputs(IncrementalExecutionContext context, CancellationToken cancellationToken) in Z:\BuildAgent\work\3b7ce003563d6f8f\src\Compilers\Core\Portable\SourceGeneration\Nodes\SourceOutputNode.cs:line 111

@skarllot, could you provide a minimal class with signatures and attributes? Thanks.

@virzak

    public partial class Subject1<T>
    {
        [Zomp.SyncMethodGenerator.CreateSyncVersion]
        public async Task FooAsync(
            )
        {
            await Task.Delay(1);
        }
    }

    public partial class Subject1
    {
        [Zomp.SyncMethodGenerator.CreateSyncVersion]
        public async Task FooAsync(
            )
        {
            await Task.Delay(1);
        }
    }
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 'SomeNamespace.Subject1.FooAsync.g.cs' of the added source file must be unique within a generator.

(ISG produces 2 files with same name - generic arguments did not taken into account).