-
Notifications
You must be signed in to change notification settings - Fork 48
Description
enum Status { Unknown = 0; Ok = 1; }
struct Hello { Status status; }
Bebop Playground with this schema
This simple schema generates C# that produces compiler .warnings in .NET 8+.
warning CS9193: Argument 1 should be a variable because it is passed to a 'ref readonly' parameter
Related to this optimization:
#189 - (re-)introduced this optimization
#301 - noticed this compiler warning started in .NET 8 and suppressed it for test package: "For some reason code that worked fine under .net 6.0 is producing warnings in 8.0 and requires a language feature bump; breaking API change in .NET? we just silence them"
I messed around in SharpLab and it looks like the whole unsafe optimization is unnecessary since the JIT compiler optimizes the simple (uint)record.Status without doing any runtime checks.
SharbLab latest compiler - all the methods are equivalent
SharbLab older compiler from C# 9 times - still has equivalent JIT optimizations
SharpLab latest compiler with serialize/deserialization
Also I went ahead and checked both directions of the enum casting to make sure they're all still equivalent.
