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