-
-
Notifications
You must be signed in to change notification settings - Fork 3.4k
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
Range syntax in combination with ?[] does not work as expected #2156
Comments
Current decompiler output: // switchTest.TestSwitch
using System;
using System.IO;
public static string Create(string url)
{
object obj;
if (!url.Contains('.'))
{
obj = url;
}
else
{
string? extension = Path.GetExtension(url);
obj = extension?[new Range(end: extension!.Length, start: 1)];
}
switch ((string)obj)
{
case "dog":
return "1";
case "fish":
case "cat":
return "2";
default:
throw new Exception("unsupported:" + url);
}
} Two/three things that should be improved:
|
This is a bit tricky. For single-assignment stack slots we can use the C# type of the expression being assigned, but that approach won't work for multiple assignments.
This is really the root cause of the issue. |
Input code
Erroneous output
Details
Try to fix
ILSpy/ICSharpCode.Decompiler/CSharp/StatementBuilder.cs
Line 151 in 41edef7
ILSpy will decompile without exception if you change line 151 to the following line:
Besides, if you uncomment the following line in Input Code, ILSpy will work correctly:
The text was updated successfully, but these errors were encountered: