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 @@ -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();

2
ICSharpCode.Decompiler/CSharp/StatementBuilder.cs

@ -210,7 +210,7 @@ namespace ICSharpCode.Decompiler.CSharp @@ -210,7 +210,7 @@ namespace ICSharpCode.Decompiler.CSharp
var oldCaseLabelMapping = caseLabelMapping;
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();

Loading…
Cancel
Save