-
-
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
Invalid decompilation of switch expression with no default case #3382
Labels
Comments
siegfriedpammer
added a commit
that referenced
this issue
Feb 20, 2025
…tch-expression implicit default-case.
siegfriedpammer
added a commit
that referenced
this issue
Feb 20, 2025
…tch-expression implicit default-case.
@siegfriedpammer I've tested the changes in #3404 and it works well but I've identified some other cases that are not handled. Inputclass IncompleteSwitchExpressionTest
{
static void Test2(ref StringComparison? c)
{
c = c switch {
null => StringComparison.Ordinal, // Problem also persists without this case
StringComparison.Ordinal => StringComparison.OrdinalIgnoreCase,
StringComparison.OrdinalIgnoreCase => StringComparison.InvariantCulture,
};
}
interface I1 { }
class C1 : I1 { }
class C2 : I1 { }
class C3 : I1 { }
static int Test3(I1 i)
{
return i switch {
C1 => 1,
C2 => 2,
C3 => 3,
};
}
} Outputinternal class IncompleteSwitchExpressionTest
{
private static void Test2(ref StringComparison? c)
{
StringComparison? stringComparison = c;
StringComparison value = default(StringComparison);
switch (stringComparison)
{
case null:
value = StringComparison.Ordinal;
break;
case StringComparison.Ordinal:
value = StringComparison.OrdinalIgnoreCase;
break;
case StringComparison.OrdinalIgnoreCase:
value = StringComparison.InvariantCulture;
break;
default:
global::<PrivateImplementationDetails>.ThrowSwitchExpressionException(stringComparison);
break;
}
c = value;
}
private interface I1 { }
private class C1 : I1 { }
private class C2 : I1 { }
private class C3 : I1 { }
private static int Test3(I1 i)
{
if (!(i is C1))
{
if (!(i is C2))
{
if (i is C3)
return 3;
global::<PrivateImplementationDetails>.ThrowSwitchExpressionException(i);
int result = default(int);
return result;
}
return 2;
}
return 1;
}
} |
Thanks for providing further test cases. Please note that your |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Input code
Erroneous output
When a switch expression does not specify a default case the compiler will add one that throws a
SwitchExpressionException
or aInvalidOperationException
on older runtimes.The decompiled code cannot recompile as
<PrivateImplementationDetails>
is not a valid identifier.Details
The text was updated successfully, but these errors were encountered: