Skip to content

Commit

Permalink
Revert "Revert "Merge pull request #65407 from Youssef1313/scoped-ide" (
Browse files Browse the repository at this point in the history
#65647)"

This reverts commit 1766515.
  • Loading branch information
ryzngard committed Dec 1, 2022
1 parent 46fa216 commit 2a5025d
Show file tree
Hide file tree
Showing 18 changed files with 1,026 additions and 101 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2617,6 +2617,45 @@ static void staticLocalFunction() { }|]
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);
}

[Theory]
[CombinatorialData]
public async Task Lambda_DefaultParameterValue(TestHost testHost)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.Completion.Providers;
using Microsoft.CodeAnalysis.CSharp;
Expand Down Expand Up @@ -11964,11 +11965,67 @@ 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_FollowedByType()
{
var source = @"
scoped $$
ref struct MyRefStruct { }
";
await VerifyItemExistsAsync(MakeMarkup(source), "MyRefStruct");
}

[Fact]
public async Task AfterScopedGlobalStatement_NotFollowedByType()
{
var source = """
using System;

scoped $$
""";

await VerifyItemExistsAsync(MakeMarkup(source), "ReadOnlySpan", displayTextSuffix: "<>");
}

[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 $$"""
<Workspace>
<Project Language="C#" AssemblyName="Assembly" CommonReferences="true" LanguageVersion="{{languageVersion}}">
<Project Language="C#" AssemblyName="Assembly" CommonReferencesNet6="true" LanguageVersion="{{languageVersion}}">
<Document FilePath="Test.cs">
{{source}}
</Document>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -510,6 +510,24 @@ void M(ref int [|p|])
}");
}

[Fact]
public async Task AssignmentThroughScopedRefLocal()
{
await TestAsync(
@"
using System;
class C
{
void M(ref int [|p|])
{
scoped ref var [|local|] = ref [|p|];
[|local|] = 0;
[|local|] = 1;
Console.WriteLine([|local|]);
}
}");
}

[Fact]
public async Task TestRefLocalReassignment()
{
Expand Down Expand Up @@ -653,6 +671,23 @@ void M()
}");
}

[Fact]
public async Task TestScopedReadonlyRefLocalWithNoReassignment()
{
await TestAsync(
@"
using System;
class C
{
void M()
{
int p = 0;
scoped ref readonly int refP = ref p;
Console.WriteLine(p);
}
}");
}

[Fact]
public async Task TestReadonlyRefLocalWithNoReassignment1()
{
Expand All @@ -670,6 +705,23 @@ void M()
}");
}

[Fact]
public async Task TestScopedReadonlyRefLocalWithNoReassignment1()
{
await TestAsync(
@"
using System;
class C
{
void M1()
{
int p = 0;
scoped ref readonly int refP = ref p!;
Console.WriteLine(p);
}
}");
}

[Fact]
public async Task TestPointerCausingPossibleReassignment()
{
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

0 comments on commit 2a5025d

Please sign in to comment.