Skip to content

Commit e4285b7

Browse files
Fix build.
1 parent efbefd0 commit e4285b7

File tree

2 files changed

+5
-8
lines changed

2 files changed

+5
-8
lines changed

ICSharpCode.Decompiler/CSharp/ExpressionBuilder.cs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3900,20 +3900,17 @@ protected internal override TranslatedExpression VisitIfInstruction(IfInstructio
39003900
}
39013901
}
39023902

3903-
internal (TranslatedExpression, IType) TranslateSwitchValue(SwitchInstruction inst, bool allowImplicitConversion)
3903+
internal (TranslatedExpression, IType, StringToInt) TranslateSwitchValue(SwitchInstruction inst, bool allowImplicitConversion)
39043904
{
39053905
TranslatedExpression value;
39063906
IType type;
39073907
if (inst.Value is StringToInt strToInt)
39083908
{
3909-
// switch-expression does not support implicit conversions at all,
3910-
// switch-statement does support implicit conversions in general, however, the rules are
3911-
// not very intuitive and in order to prevent bugs, we emit an explicit cast.
39123909
value = Translate(strToInt.Argument)
39133910
.ConvertTo(
39143911
strToInt.ExpectedType,
39153912
this,
3916-
allowImplicitConversion: false
3913+
allowImplicitConversion: allowImplicitConversion
39173914
);
39183915
type = compilation.FindType(KnownTypeCode.String);
39193916
}
@@ -3928,13 +3925,13 @@ protected internal override TranslatedExpression VisitIfInstruction(IfInstructio
39283925
type = inst.Type;
39293926
}
39303927
}
3931-
return (value, type);
3928+
return (value, type, strToInt);
39323929
}
39333930

39343931
protected internal override TranslatedExpression VisitSwitchInstruction(SwitchInstruction inst, TranslationContext context)
39353932
{
39363933
// switch-expression does not support implicit conversions
3937-
var (value, type) = TranslateSwitchValue(inst, allowImplicitConversion: false);
3934+
var (value, type, strToInt) = TranslateSwitchValue(inst, allowImplicitConversion: false);
39383935

39393936
IL.SwitchSection defaultSection = inst.GetDefaultSection();
39403937
SwitchExpression switchExpr = new SwitchExpression();

ICSharpCode.Decompiler/CSharp/StatementBuilder.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ SwitchStatement TranslateSwitch(BlockContainer switchContainer, SwitchInstructio
210210
var oldCaseLabelMapping = caseLabelMapping;
211211
caseLabelMapping = new Dictionary<Block, ConstantResolveResult>();
212212

213-
var (value, type) = exprBuilder.TranslateSwitchValue(inst, allowImplicitConversion: true);
213+
var (value, type, strToInt) = exprBuilder.TranslateSwitchValue(inst, allowImplicitConversion: true);
214214

215215
IL.SwitchSection defaultSection = inst.GetDefaultSection();
216216

0 commit comments

Comments
 (0)