Skip to content

Commit

Permalink
Merge pull request #67097 from CyrusNajmabadi/stringRecommender
Browse files Browse the repository at this point in the history
Do not offer `string` (or other type-keywords) after `ref/readonly` inside namespace member declaration
  • Loading branch information
CyrusNajmabadi authored Mar 6, 2023
2 parents c10fcd3 + 14551b3 commit 5f38bc8
Show file tree
Hide file tree
Showing 31 changed files with 1,681 additions and 36 deletions.
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

0 comments on commit 5f38bc8

Please sign in to comment.