|
|
|
@ -3900,20 +3900,17 @@ namespace ICSharpCode.Decompiler.CSharp
@@ -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
@@ -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(); |
|
|
|
|