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

Work some 'scoped' issues on IDE #65407

Merged
merged 18 commits into from
Nov 24, 2022
Merged
Show file tree
Hide file tree
Changes from 11 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 @@ -2616,5 +2616,44 @@ static void staticLocalFunction() { }|]
Punctuation.OpenCurly,
Punctuation.CloseCurly);
}

[Theory]
[CombinatorialData]
public async Task TestScopedVar(TestHost testHost)
{
await TestAsync("""
static void method(scoped in S s)
{
scoped var rs1 = s;
}

file readonly ref struct S { }
""", testHost,
Keyword("static"),
Keyword("void"),
Method("method"),
Static("method"),
Punctuation.OpenParen,
Keyword("scoped"),
Keyword("in"),
Struct("S"),
Parameter("s"),
Punctuation.CloseParen,
Punctuation.OpenCurly,
Keyword("scoped"),
Keyword("var"),
Local("rs1"),
Operators.Equals,
Parameter("s"),
Punctuation.Semicolon,
Punctuation.CloseCurly,
Keyword("file"),
Keyword("readonly"),
Keyword("ref"),
Keyword("struct"),
Struct("S"),
Punctuation.OpenCurly,
Punctuation.CloseCurly);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11896,6 +11896,50 @@ class C
await VerifyAnyItemExistsAsync(source);
}

[Fact]
public async Task AfterScopedInsideMethod()
{
var source = @"
class C
{
void M()
{
scoped $$
}
}

ref struct MyRefStruct { }
";
await VerifyItemExistsAsync(MakeMarkup(source), "MyRefStruct");
}

[Fact]
public async Task AfterScopedGlobalStatement()
{
var source = @"
scoped $$

ref struct MyRefStruct { }
";
await VerifyItemExistsAsync(MakeMarkup(source), "MyRefStruct");
}

[Fact]
public async Task AfterScopedInParameter()
{
var source = @"
class C
{
void M(scoped $$)
{
}
}

ref struct MyRefStruct { }
";
await VerifyItemExistsAsync(MakeMarkup(source), "MyRefStruct");
}

private static string MakeMarkup(string source, string languageVersion = "Preview")
{
return $$"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -500,13 +500,21 @@ await TestAsync(
using System;
class C
{
void M(ref int [|p|])
void M1(ref int [|p|])
Youssef1313 marked this conversation as resolved.
Show resolved Hide resolved
{
ref var [|local|] = ref [|p|];
[|local|] = 0;
[|local|] = 1;
Console.WriteLine([|local|]);
}

void M2(ref int [|p|])
{
scoped ref var [|local|] = ref [|p|];
[|local|] = 0;
[|local|] = 1;
Console.WriteLine([|local|]);
}
}");
}

Expand Down Expand Up @@ -644,12 +652,19 @@ await TestAsync(
using System;
class C
{
void M()
void M1()
{
int p = 0;
ref readonly int refP = ref p;
Console.WriteLine(p);
}

void M2()
{
int p = 0;
scoped ref readonly int refP = ref p;
Console.WriteLine(p);
}
}");
}

Expand All @@ -661,12 +676,19 @@ await TestAsync(
using System;
class C
{
void M()
void M1()
{
int p = 0;
ref readonly int refP = ref p!;
Console.WriteLine(p);
}

void M2()
{
int p = 0;
scoped ref readonly int refP = ref p!;
Console.WriteLine(p);
}
}");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -349,5 +349,12 @@ await VerifyKeywordAsync(
@"$$
[assembly: Call()]");
}

[Fact]
public async Task TestAfterScoped()
{
await VerifyKeywordAsync("scoped $$");
await VerifyKeywordAsync(AddInsideMethod("scoped $$"));
}
}
}
Loading