Skip to content

Commit

Permalink
Add test for undefined behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
alrz committed Nov 12, 2021
1 parent cb5efa4 commit 37714bf
Showing 1 changed file with 30 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5626,6 +5626,36 @@ public void Subsumption_Slice_03()
);
}

[Fact]
public void Subsumption_Slice_04()
{
var source = @"
#nullable enable
class C
{
public int Length => 3;
public int this[int i] => 0;
public int[]? Slice(int i, int j) => null;
public static void Main()
{
switch (new C())
{
case [.. {}]:
break;
case [.. null]:
break;
}
}
}
";
var compilation = CreateCompilation(source, options: TestOptions.ReleaseExe);
compilation.VerifyEmitDiagnostics(
// (15,18): error CS8120: The switch case is unreachable. It has already been handled by a previous case or it is impossible to match.
// case [.. null]:
Diagnostic(ErrorCode.ERR_SwitchCaseSubsumed, "[.. null]").WithLocation(15, 18));
}

[Fact]
public void Exhaustiveness_01()
{
Expand Down

0 comments on commit 37714bf

Please sign in to comment.