-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
System.Text.Json emits uncompilable code #103515
Comments
Tagging subscribers to this area: @dotnet/area-system-text-json, @gregsdennis |
The minimum language version currently supported by the STJ generator is C# 9 so I think we can replace |
Would love to @eiriktsarpalis . Hopefully do it this weekend (if I can remember how, it's been a while!) |
In the meantime, you could try disabling fast-path serialization as a workaround: [JsonSourceGenerationOptions(GenerationMode = JsonSourceGenerationMode.Metadata)]
[JsonSerializable(typeof(Foo))]
internal partial class JsonSourceGenerationContext : JsonSerializerContext; |
Description
I had a bug report for my open source source generator project:
SteveDunn/Vogen#622
I looked at the emitted code and can see that it emits
value == null
rather thanvalue is null
. This caused a compilation error because the type in question has overloaded==
operators, so the C# compiler reports:CS0034: Operator '==' is ambiguous on operands of type 'Foo' and '<null>'
The line in question in STJ is here: https://github.com/dotnet/runtime/blob/main/src/libraries/System.Text.Json/gen/JsonSourceGenerator.Emitter.cs#L977
Reproduction Steps
This should compile, but doesn't. Instead, the compiler reports:
CS0034: Operator '==' is ambiguous on operands of type 'Foo' and '<null>'
Expected behavior
For it to compile
Actual behavior
Emits error
CS0034: Operator '==' is ambiguous on operands of type 'Foo' and '<null>'
Regression?
No, I think the source generator stuff in STJ is fairly new
Known Workarounds
If I change my type from a
class
to astruct
, then the null check isn't emitted.Configuration
.NET 8, Windows 11, X64, not specific to any particular configuration.
Other information
I plan on doing a fix and a PR
The text was updated successfully, but these errors were encountered: