diff --git a/ICSharpCode.Decompiler/CSharp/ExpressionBuilder.cs b/ICSharpCode.Decompiler/CSharp/ExpressionBuilder.cs index dfec27d8d..9f53f9c89 100644 --- a/ICSharpCode.Decompiler/CSharp/ExpressionBuilder.cs +++ b/ICSharpCode.Decompiler/CSharp/ExpressionBuilder.cs @@ -3900,20 +3900,17 @@ namespace ICSharpCode.Decompiler.CSharp } } - internal (TranslatedExpression, IType) TranslateSwitchValue(SwitchInstruction inst, bool allowImplicitConversion) + internal (TranslatedExpression, IType, StringToInt) TranslateSwitchValue(SwitchInstruction inst, bool allowImplicitConversion) { TranslatedExpression value; IType type; if (inst.Value is StringToInt strToInt) { - // switch-expression does not support implicit conversions at all, - // switch-statement does support implicit conversions in general, however, the rules are - // not very intuitive and in order to prevent bugs, we emit an explicit cast. value = Translate(strToInt.Argument) .ConvertTo( strToInt.ExpectedType, this, - allowImplicitConversion: false + allowImplicitConversion: allowImplicitConversion ); type = compilation.FindType(KnownTypeCode.String); } @@ -3928,13 +3925,13 @@ namespace ICSharpCode.Decompiler.CSharp type = inst.Type; } } - return (value, type); + return (value, type, strToInt); } protected internal override TranslatedExpression VisitSwitchInstruction(SwitchInstruction inst, TranslationContext context) { // switch-expression does not support implicit conversions - var (value, type) = TranslateSwitchValue(inst, allowImplicitConversion: false); + var (value, type, strToInt) = TranslateSwitchValue(inst, allowImplicitConversion: false); IL.SwitchSection defaultSection = inst.GetDefaultSection(); SwitchExpression switchExpr = new SwitchExpression(); diff --git a/ICSharpCode.Decompiler/CSharp/StatementBuilder.cs b/ICSharpCode.Decompiler/CSharp/StatementBuilder.cs index 52fcb2302..a806e8bb7 100644 --- a/ICSharpCode.Decompiler/CSharp/StatementBuilder.cs +++ b/ICSharpCode.Decompiler/CSharp/StatementBuilder.cs @@ -210,7 +210,7 @@ namespace ICSharpCode.Decompiler.CSharp var oldCaseLabelMapping = caseLabelMapping; caseLabelMapping = new Dictionary(); - var (value, type) = exprBuilder.TranslateSwitchValue(inst, allowImplicitConversion: true); + var (value, type, strToInt) = exprBuilder.TranslateSwitchValue(inst, allowImplicitConversion: true); IL.SwitchSection defaultSection = inst.GetDefaultSection();