Version Used: 5.0.302
Steps to Reproduce:
Given this method:
private static string GetTextBuggy(Position? position, Wrap wrap) {
return position switch {
not Position.First when wrap.Sub is Zero => "Not First and Zero",
null => "Null",
_ when wrap is {
Sub: One or Two
} => "One or Two",
Position.Last => "Last",
Position.First => "First",
_ => "Other"
};
}
This is called with argument values Position.First and Wrap { Sub = new Zero() }.
Expected Behavior: The return value is "First"
Actual Behavior: The return value is "Other".
Remarks: The code works as expected when the or pattern is split into to cases:
private static string GetTextWorkaround(Position? position, Wrap wrap) {
return position switch {
not Position.First when wrap.Sub is Zero => "Not First and Zero",
null => "Null",
_ when wrap is {
Sub: One
} => "Just one",
_ when wrap is {
Sub: Two
} => "Just two",
Position.Last => "Last",
Position.First => "First",
_ => "Other"
};
}
Complete project: Switcher.zip
Version Used: 5.0.302
Steps to Reproduce:
Given this method:
This is called with argument values
Position.FirstandWrap { Sub = new Zero() }.Expected Behavior: The return value is "First"
Actual Behavior: The return value is "Other".
Remarks: The code works as expected when the
orpattern is split into to cases:Complete project: Switcher.zip