eiriktsarpalis / PolyType

Practical generic programming for C#
https://eiriktsarpalis.github.io/PolyType/
MIT License
145 stars 6 forks source link

Generating a witness of an enum type produces a compile error in the source generated code #29

Closed AArnott closed 2 weeks ago

AArnott commented 2 weeks ago

When I add this to the TypeShape.Tests project:

[GenerateShape<MyEnum>]
partial class Witness { }

I get this compile error:

Q:\source\typeshape-csharp\tests\TypeShape.Tests\obj\Debug\net8.0\generated\TypeShape.SourceGenerator\TypeShape.SourceGenerator.TypeShapeIncrementalGenerator\TypeShape.Tests.MsgPackSerializerTests.Witness.MyEnum.g.cs(25,38,25,43): error CS0119: 'int' is a type, which is not valid in the given context

which points to this generated code:

private global::TypeShape.Abstractions.ITypeShape<global::TypeShape.Tests.MyEnum> Create_MyEnum()
{
    return new global::TypeShape.SourceGenModel.SourceGenEnumTypeShape<global::TypeShape.Tests.MyEnum, int>
    {
        UnderlyingType = Int32, // error on this line
        Provider = this,
    };
}

I can workaround it by adding yet another witness explicitly:

+[GenerateShape<int>]
 [GenerateShape<MyEnum>]
 partial class Witness { }

But having to do that seems very tedious. Shouldn't transitive types like this be implicit?

eiriktsarpalis commented 2 weeks ago

Thanks. It would seem like the shape of the underlying type isn't being generated.