Skip to content

Commit

Permalink
Consider next statement when analyzing nested switch statements
Browse files Browse the repository at this point in the history
  • Loading branch information
alrz committed Aug 15, 2019
1 parent 1cd3268 commit c69a5d9
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public async Task TestNested_01()
{
await TestInCSharp8(
@"class Program
{
{
int M(int i, int j)
{
int r;
Expand Down Expand Up @@ -96,7 +96,7 @@ int M(int i, int j)
}
}",
@"class Program
{
{
int M(int i, int j)
{
var r = i switch
Expand Down Expand Up @@ -126,35 +126,31 @@ int M(int i, int j)
y = 1;
break;
}
switch (i)
return i switch
{
default:
throw null;
case 1:
return j switch
{
10 => 10,
20 => 20,
30 => 30,
_ => 0,
};
case 2:
return j switch
{
10 => 10,
20 => 20,
30 => 30,
var _ => 0,
};
case 3:
return j switch
{
10 => 10,
20 => 20,
30 => 30,
var v => 0,
};
}
1 => j switch
{
10 => 10,
20 => 20,
30 => 30,
_ => 0,
},
2 => j switch
{
10 => 10,
20 => 20,
30 => 30,
var _ => 0,
},
3 => j switch
{
10 => 10,
20 => 20,
30 => 30,
var v => 0,
},
_ => throw null,
};
}
}");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ private SyntaxKind AnalyzeSwitchSection(SwitchSectionSyntax section)
switch (section.Statements.Count)
{
case 1:
case 2 when section.Statements[1].IsKind(SyntaxKind.BreakStatement):
case 2 when section.Statements[1].IsKind(SyntaxKind.BreakStatement) || section.Statements[0].IsKind(SyntaxKind.SwitchStatement):
return Visit(section.Statements[0]);
default:
return default;
Expand Down

0 comments on commit c69a5d9

Please sign in to comment.