Browse Source

Fix #2222: switch-expression does not support implicit conversions.

pull/2235/head
Siegfried Pammer 5 years ago
parent
commit
cfaf6cc93f
  1. 19
      ICSharpCode.Decompiler.Tests/TestCases/Pretty/SwitchExpressions.cs
  2. 2
      ICSharpCode.Decompiler/CSharp/ExpressionBuilder.cs

19
ICSharpCode.Decompiler.Tests/TestCases/Pretty/SwitchExpressions.cs

@ -22,6 +22,14 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
{ {
public static class SwitchExpressions public static class SwitchExpressions
{ {
public class ImplicitlyCastToString
{
public static implicit operator string(ImplicitlyCastToString val)
{
return "foo";
}
}
public enum State public enum State
{ {
False, False,
@ -146,5 +154,16 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
return "Default"; return "Default";
} }
} }
public static string Issue2222()
{
return (string)new ImplicitlyCastToString() switch
{
"foo" => "foo",
"bar" => "bar",
"quux" => "quux",
_ => "default",
};
}
} }
} }

2
ICSharpCode.Decompiler/CSharp/ExpressionBuilder.cs

@ -3627,7 +3627,7 @@ namespace ICSharpCode.Decompiler.CSharp
.ConvertTo( .ConvertTo(
typeSystem.FindType(KnownTypeCode.String), typeSystem.FindType(KnownTypeCode.String),
this, this,
allowImplicitConversion: true allowImplicitConversion: false // switch-expression does not support implicit conversions
); );
} }
else else

Loading…
Cancel
Save