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

Unions generate code that is not C#7 compliant #304

Closed
jsupnik-ext-sd opened this issue Jun 18, 2024 · 1 comment
Closed

Unions generate code that is not C#7 compliant #304

jsupnik-ext-sd opened this issue Jun 18, 2024 · 1 comment

Comments

@jsupnik-ext-sd
Copy link

jsupnik-ext-sd commented Jun 18, 2024

I have a library that uses C#8 and targets the .net 2.1 standard framework. One of the serialized types is abstract, so I've implemented it as a union in MemoryPack.

MemoryPackGenerator.Emitter.cs generates the following code:

static readonly System.Collections.Generic.Dictionary<Type, ushort> __typeToTag = new(28)

This code causes the compiler to emit the error:

Feature 'target-typed object creation' is not available. Please use language version 9.0 or greater.

A google search of this error message suggests that the issue is the new key word without a corresponding object type after the new.

I believe this problem can be fixed in the source generator by changing line 1092 from:

    static readonly System.Collections.Generic.Dictionary<Type, ushort> __typeToTag = new({{UnionTags.Length}})

to

    static readonly System.Collections.Generic.Dictionary<Type, ushort> __typeToTag = new System.Collections.Generic.Dictionary<Type, ushort>({{UnionTags.Length}})

I'm going to look into creating a PR with a fix for this, but I've never contributed to an OSS project before, so it may take me some time to figure out how to do so.

@jsupnik-ext-sd
Copy link
Author

I've created a PR to address this issue: #305 but don't know how to add reviewers.

@neuecc neuecc closed this as completed Jul 30, 2024
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

No branches or pull requests

2 participants