Skip to content

Commit

Permalink
Test local functions with goto out of scope (#73402)
Browse files Browse the repository at this point in the history
  • Loading branch information
jjonescz authored May 14, 2024
1 parent 9b6dd87 commit cc82c05
Showing 1 changed file with 53 additions and 0 deletions.
53 changes: 53 additions & 0 deletions src/Compilers/CSharp/Test/Emit/CodeGen/GotoTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -606,6 +606,59 @@ public void GotoInLambda_NonExistent()
Diagnostic(ErrorCode.ERR_LabelNotFound, "x").WithArguments("x").WithLocation(4, 10));
}

[Fact, WorkItem("https://github.com/dotnet/roslyn/issues/73397")]
public void GotoInLocalFunc_OutOfScope_Backward()
{
var code = """
#pragma warning disable CS8321 // local function unused
x:
void localFunc()
{
using System.IDisposable d = null;
goto x;
}
""";
CreateCompilation(code).VerifyEmitDiagnostics(
// (6,5): error CS0159: No such label 'x' within the scope of the goto statement
// goto x;
Diagnostic(ErrorCode.ERR_LabelNotFound, "goto").WithArguments("x").WithLocation(6, 5));
}

[Fact, WorkItem("https://github.com/dotnet/roslyn/issues/73397")]
public void GotoInLocalFunc_OutOfScope_Forward()
{
var code = """
#pragma warning disable CS8321 // local function unused
void localFunc()
{
using System.IDisposable d = null;
goto x;
}
x:;
""";
CreateCompilation(code).VerifyEmitDiagnostics(
// (5,5): error CS0159: No such label 'x' within the scope of the goto statement
// goto x;
Diagnostic(ErrorCode.ERR_LabelNotFound, "goto").WithArguments("x").WithLocation(5, 5));
}

[Fact, WorkItem("https://github.com/dotnet/roslyn/issues/73397")]
public void GotoInLocalFunc_NonExistent()
{
var code = """
#pragma warning disable CS8321 // local function unused
void localFunc()
{
using System.IDisposable d = null;
goto x;
}
""";
CreateCompilation(code).VerifyEmitDiagnostics(
// (5,10): error CS0159: No such label 'x' within the scope of the goto statement
// goto x;
Diagnostic(ErrorCode.ERR_LabelNotFound, "x").WithArguments("x").WithLocation(5, 10));
}

// Definition same label in different lambdas
[WorkItem(5991, "DevDiv_Projects/Roslyn")]
[Fact]
Expand Down

0 comments on commit cc82c05

Please sign in to comment.