Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
AArnott opened this issue Oct 26, 2024 · 1 comment · Fixed by #30
Closed

Comments

@AArnott
Copy link
Contributor

AArnott commented Oct 26, 2024

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
Copy link
Owner

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants