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

Do not offer string (or other type-keywords) after ref/readonly inside namespace member declaration #67097

Merged
merged 6 commits into from
Mar 6, 2023
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -799,5 +799,114 @@ class C
required $$
}");
}

[Fact, WorkItem(67061, "https://github.com/dotnet/roslyn/issues/67061")]
public async Task TestAfterRefAtTopLevel1()
{
// Could be defining a ref-local in top-level-code
await VerifyKeywordAsync(
@"ref $$");
}

[Theory, WorkItem(67061, "https://github.com/dotnet/roslyn/issues/67061")]
[CombinatorialData]
public async Task TestAfterReadonlyAtTopLevel1(bool script)
{
if (script)
{
// A legal top level script field.
await VerifyKeywordAsync(
@"readonly $$", Options.Script);
}
else
{
// no legal top level statement can start with `readonly string`
await VerifyAbsenceAsync(
@"readonly $$", CSharp9ParseOptions, CSharp9ParseOptions);
}
}

[Fact, WorkItem(67061, "https://github.com/dotnet/roslyn/issues/67061")]
public async Task TestAfterRefReadonlyAtTopLevel1()
{
// Could be defining a ref-local in top-level-code
await VerifyKeywordAsync(
@"ref readonly $$");
}

[Fact, WorkItem(67061, "https://github.com/dotnet/roslyn/issues/67061")]
public async Task TestNotAfterRefInNamespace()
{
// This is only legal for a struct declaration
await VerifyAbsenceAsync(
@"namespace N
{
ref $$
}");
}

[Fact, WorkItem(67061, "https://github.com/dotnet/roslyn/issues/67061")]
public async Task TestNotAfterReadonlyInNamespace()
{
// This is only legal for a struct declaration
await VerifyAbsenceAsync(
@"namespace N
{
readonly $$
}");
}

[Fact, WorkItem(67061, "https://github.com/dotnet/roslyn/issues/67061")]
public async Task TestNotAfterRefReadonlyInNamespace()
{
// This is only legal for a struct declaration
await VerifyAbsenceAsync(
@"namespace N
{
ref readonly $$
}");
}

[Theory, WorkItem(67061, "https://github.com/dotnet/roslyn/issues/67061")]
[InlineData("class")]
[InlineData("interface")]
[InlineData("struct")]
[InlineData("record")]
public async Task TestAfterRefInClassInterfaceStructRecord(string type)
{
await VerifyKeywordAsync(
$@"{type} N
{{
ref $$
}}");
}

[Theory, WorkItem(67061, "https://github.com/dotnet/roslyn/issues/67061")]
[InlineData("class")]
[InlineData("interface")]
[InlineData("struct")]
[InlineData("record")]
public async Task TestAfterReadonlyInClassInterfaceStructRecord(string type)
{
await VerifyKeywordAsync(
$@"{type} N
{{
readonly $$
}}");
}

[Theory, WorkItem(67061, "https://github.com/dotnet/roslyn/issues/67061")]
[InlineData("class")]
[InlineData("interface")]
[InlineData("struct")]
[InlineData("record")]
public async Task TestAfterRefReadonlyInClassInterfaceStructRecord(string type)
{
await VerifyKeywordAsync(
$@"{type} N
{{
ref readonly $$
}}");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -800,5 +800,114 @@ class C
required $$
}");
}

[Fact, WorkItem(67061, "https://github.com/dotnet/roslyn/issues/67061")]
public async Task TestAfterRefAtTopLevel1()
{
// Could be defining a ref-local in top-level-code
await VerifyKeywordAsync(
@"ref $$");
}

[Theory, WorkItem(67061, "https://github.com/dotnet/roslyn/issues/67061")]
[CombinatorialData]
public async Task TestAfterReadonlyAtTopLevel1(bool script)
{
if (script)
{
// A legal top level script field.
await VerifyKeywordAsync(
@"readonly $$", Options.Script);
}
else
{
// no legal top level statement can start with `readonly string`
await VerifyAbsenceAsync(
@"readonly $$", CSharp9ParseOptions, CSharp9ParseOptions);
}
}

[Fact, WorkItem(67061, "https://github.com/dotnet/roslyn/issues/67061")]
public async Task TestAfterRefReadonlyAtTopLevel1()
{
// Could be defining a ref-local in top-level-code
await VerifyKeywordAsync(
@"ref readonly $$");
}

[Fact, WorkItem(67061, "https://github.com/dotnet/roslyn/issues/67061")]
public async Task TestNotAfterRefInNamespace()
{
// This is only legal for a struct declaration
await VerifyAbsenceAsync(
@"namespace N
{
ref $$
}");
}

[Fact, WorkItem(67061, "https://github.com/dotnet/roslyn/issues/67061")]
public async Task TestNotAfterReadonlyInNamespace()
{
// This is only legal for a struct declaration
await VerifyAbsenceAsync(
@"namespace N
{
readonly $$
}");
}

[Fact, WorkItem(67061, "https://github.com/dotnet/roslyn/issues/67061")]
public async Task TestNotAfterRefReadonlyInNamespace()
{
// This is only legal for a struct declaration
await VerifyAbsenceAsync(
@"namespace N
{
ref readonly $$
}");
}

[Theory, WorkItem(67061, "https://github.com/dotnet/roslyn/issues/67061")]
[InlineData("class")]
[InlineData("interface")]
[InlineData("struct")]
[InlineData("record")]
public async Task TestAfterRefInClassInterfaceStructRecord(string type)
{
await VerifyKeywordAsync(
$@"{type} N
{{
ref $$
}}");
}

[Theory, WorkItem(67061, "https://github.com/dotnet/roslyn/issues/67061")]
[InlineData("class")]
[InlineData("interface")]
[InlineData("struct")]
[InlineData("record")]
public async Task TestAfterReadonlyInClassInterfaceStructRecord(string type)
{
await VerifyKeywordAsync(
$@"{type} N
{{
readonly $$
}}");
}

[Theory, WorkItem(67061, "https://github.com/dotnet/roslyn/issues/67061")]
[InlineData("class")]
[InlineData("interface")]
[InlineData("struct")]
[InlineData("record")]
public async Task TestAfterRefReadonlyInClassInterfaceStructRecord(string type)
{
await VerifyKeywordAsync(
$@"{type} N
{{
ref readonly $$
}}");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -839,5 +839,114 @@ class C
required $$
}");
}

[Fact, WorkItem(67061, "https://github.com/dotnet/roslyn/issues/67061")]
public async Task TestAfterRefAtTopLevel1()
{
// Could be defining a ref-local in top-level-code
await VerifyKeywordAsync(
@"ref $$");
}

[Theory, WorkItem(67061, "https://github.com/dotnet/roslyn/issues/67061")]
[CombinatorialData]
public async Task TestAfterReadonlyAtTopLevel1(bool script)
{
if (script)
{
// A legal top level script field.
await VerifyKeywordAsync(
@"readonly $$", Options.Script);
}
else
{
// no legal top level statement can start with `readonly string`
await VerifyAbsenceAsync(
@"readonly $$", CSharp9ParseOptions, CSharp9ParseOptions);
}
}

[Fact, WorkItem(67061, "https://github.com/dotnet/roslyn/issues/67061")]
public async Task TestAfterRefReadonlyAtTopLevel1()
{
// Could be defining a ref-local in top-level-code
await VerifyKeywordAsync(
@"ref readonly $$");
}

[Fact, WorkItem(67061, "https://github.com/dotnet/roslyn/issues/67061")]
public async Task TestNotAfterRefInNamespace()
{
// This is only legal for a struct declaration
await VerifyAbsenceAsync(
@"namespace N
{
ref $$
}");
}

[Fact, WorkItem(67061, "https://github.com/dotnet/roslyn/issues/67061")]
public async Task TestNotAfterReadonlyInNamespace()
{
// This is only legal for a struct declaration
await VerifyAbsenceAsync(
@"namespace N
{
readonly $$
}");
}

[Fact, WorkItem(67061, "https://github.com/dotnet/roslyn/issues/67061")]
public async Task TestNotAfterRefReadonlyInNamespace()
{
// This is only legal for a struct declaration
await VerifyAbsenceAsync(
@"namespace N
{
ref readonly $$
}");
}

[Theory, WorkItem(67061, "https://github.com/dotnet/roslyn/issues/67061")]
[InlineData("class")]
[InlineData("interface")]
[InlineData("struct")]
[InlineData("record")]
public async Task TestAfterRefInClassInterfaceStructRecord(string type)
{
await VerifyKeywordAsync(
$@"{type} N
{{
ref $$
}}");
}

[Theory, WorkItem(67061, "https://github.com/dotnet/roslyn/issues/67061")]
[InlineData("class")]
[InlineData("interface")]
[InlineData("struct")]
[InlineData("record")]
public async Task TestAfterReadonlyInClassInterfaceStructRecord(string type)
{
await VerifyKeywordAsync(
$@"{type} N
{{
readonly $$
}}");
}

[Theory, WorkItem(67061, "https://github.com/dotnet/roslyn/issues/67061")]
[InlineData("class")]
[InlineData("interface")]
[InlineData("struct")]
[InlineData("record")]
public async Task TestAfterRefReadonlyInClassInterfaceStructRecord(string type)
{
await VerifyKeywordAsync(
$@"{type} N
{{
ref readonly $$
}}");
}
}
}
Loading