Browse Source

Fix build.

pull/3362/head
Siegfried Pammer 4 months ago
parent
commit
e4285b751b
  1. 11
      ICSharpCode.Decompiler/CSharp/ExpressionBuilder.cs
  2. 2
      ICSharpCode.Decompiler/CSharp/StatementBuilder.cs

11
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; TranslatedExpression value;
IType type; IType type;
if (inst.Value is StringToInt strToInt) 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) value = Translate(strToInt.Argument)
.ConvertTo( .ConvertTo(
strToInt.ExpectedType, strToInt.ExpectedType,
this, this,
allowImplicitConversion: false allowImplicitConversion: allowImplicitConversion
); );
type = compilation.FindType(KnownTypeCode.String); type = compilation.FindType(KnownTypeCode.String);
} }
@ -3928,13 +3925,13 @@ namespace ICSharpCode.Decompiler.CSharp
type = inst.Type; type = inst.Type;
} }
} }
return (value, type); return (value, type, strToInt);
} }
protected internal override TranslatedExpression VisitSwitchInstruction(SwitchInstruction inst, TranslationContext context) protected internal override TranslatedExpression VisitSwitchInstruction(SwitchInstruction inst, TranslationContext context)
{ {
// switch-expression does not support implicit conversions // 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(); IL.SwitchSection defaultSection = inst.GetDefaultSection();
SwitchExpression switchExpr = new SwitchExpression(); SwitchExpression switchExpr = new SwitchExpression();

2
ICSharpCode.Decompiler/CSharp/StatementBuilder.cs

@ -210,7 +210,7 @@ namespace ICSharpCode.Decompiler.CSharp
var oldCaseLabelMapping = caseLabelMapping; var oldCaseLabelMapping = caseLabelMapping;
caseLabelMapping = new Dictionary<Block, ConstantResolveResult>(); caseLabelMapping = new Dictionary<Block, ConstantResolveResult>();
var (value, type) = exprBuilder.TranslateSwitchValue(inst, allowImplicitConversion: true); var (value, type, strToInt) = exprBuilder.TranslateSwitchValue(inst, allowImplicitConversion: true);
IL.SwitchSection defaultSection = inst.GetDefaultSection(); IL.SwitchSection defaultSection = inst.GetDefaultSection();

Loading…
Cancel
Save