Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test local functions with goto out of scope #73402

Merged
merged 1 commit into from
May 14, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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