Skip to content

Commit

Permalink
Merge pull request #9 from eNeRGy164/feature/switch-when-clause
Browse files Browse the repository at this point in the history
Don't ignore pattern when using when clause in switch case.
  • Loading branch information
eNeRGy164 authored Jan 7, 2020
2 parents d35010e + 5bb99e7 commit 3fa2ef3
Showing 1 changed file with 7 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,13 @@ private static string Label(SwitchLabelSyntax label)
switch (label)
{
case CasePatternSwitchLabelSyntax casePatternLabel:
return casePatternLabel.WhenClause?.Condition?.ToString() ?? casePatternLabel.Pattern?.ToString();
var condition = casePatternLabel.WhenClause?.Condition?.ToString();
if (condition == null)
{
return casePatternLabel.Pattern?.ToString();
}

return $"{casePatternLabel.Pattern} when {condition}";

case CaseSwitchLabelSyntax caseLabel:
return caseLabel.Value.ToString();
Expand Down

0 comments on commit 3fa2ef3

Please sign in to comment.