ILSpy
ILSpy copied to clipboard
Switch Expression Decompilation Bug with Docs.msft Sample
Sample in question: https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/operators/switch-expression (basic example)
Output in ILSpy (latest master):
Seems the default case that is compiler-generated makes ILSpy stumble on pattern detection.
I'd argue this is a bug in roslyn, WTF is it doing with those if (1 == 0)
checks?
Do we now need a de-obfuscation step for regular C# decompilation?
I built the sample using VS Preview and the .NET 5 tooling. Code & binaries attached (might differ to RTM Roslyn).
The thing is: switch
expressions missing the _ =>
case have a default: throw new SwitchExpressionException(...);
implicitly added. We should remove these.
About the if (1 == 0)
... no idea... we have seen similar blocks while implementing the async enumerator patterns, iirc.
I don't think we should remove the throw new SwitchExpressionException
; I'd like to keep that explicit.
But it's perfectly fine to have a throw expression in a switch expression (and this is already implemented); the only problem here is the if (1 == 0)
.
I just discovered this aswell and found out this only occurs in Assemblies compiled with debug-Configuration. Thought I'd share my observation. I'd guess it's something like a Placeholder for debug purposes?