mirror of
https://github.com/icsharpcode/ILSpy.git
synced 2026-10-12 02:15:58 +00:00
Fix throw switch-expr; by specifying the typeHint for throw.
This commit is contained in:
@@ -244,6 +244,15 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
|
||||
}).ToValidated();
|
||||
}
|
||||
|
||||
public static void ThrowDifferentExceptions(int i)
|
||||
{
|
||||
throw i switch {
|
||||
0 => (Exception)new ArgumentException("Invalid argument"),
|
||||
1 => new InvalidOperationException("Invalid operation"),
|
||||
_ => new NotSupportedException(),
|
||||
};
|
||||
}
|
||||
|
||||
public static int SwitchOnStringImplicitDefault(string s)
|
||||
{
|
||||
return s switch {
|
||||
|
||||
@@ -1272,7 +1272,8 @@ namespace ICSharpCode.Decompiler.CSharp
|
||||
|
||||
protected internal override TranslatedExpression VisitThrow(Throw inst, TranslationContext context)
|
||||
{
|
||||
return new ThrowExpression(Translate(inst.Argument))
|
||||
var ex = Translate(inst.Argument, typeHint: compilation.FindType(KnownTypeCode.Exception));
|
||||
return new ThrowExpression(ex)
|
||||
.WithILInstruction(inst)
|
||||
.WithRR(new ThrowResolveResult());
|
||||
}
|
||||
|
||||
@@ -434,7 +434,8 @@ namespace ICSharpCode.Decompiler.CSharp
|
||||
|
||||
protected internal override TranslatedStatement VisitThrow(Throw inst)
|
||||
{
|
||||
return new ThrowStatement(exprBuilder.Translate(inst.Argument)).WithILInstruction(inst);
|
||||
var ex = exprBuilder.Translate(inst.Argument, typeHint: typeSystem.FindType(KnownTypeCode.Exception));
|
||||
return new ThrowStatement(ex).WithILInstruction(inst);
|
||||
}
|
||||
|
||||
protected internal override TranslatedStatement VisitRethrow(Rethrow inst)
|
||||
|
||||
Reference in New Issue
Block a user