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

Merge PrimaryConstructors into Main #67124

Merged
merged 32 commits into from
Mar 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
92ea6a9
Merge 'main' into 'PrimaryConstructors' (#65755)
AlekseyTs Dec 5, 2022
8c2cfad
Implement parsing changes for Primary Constructors feature (#65720)
AlekseyTs Dec 6, 2022
cfb509f
Bind an emit Primary Constructor (#65899)
AlekseyTs Dec 18, 2022
4a646b2
Merge remote-tracking branch 'dotnet/main' into PrimaryConstructors
AlekseyTs Dec 18, 2022
ccf248c
Fix formatting
AlekseyTs Dec 18, 2022
397ce34
Merge 'main' into 'PrimaryConstructors' (#66053)
AlekseyTs Dec 18, 2022
e76e58c
Implement new lookup rules for Primary Constructor parameters (#66054)
AlekseyTs Jan 5, 2023
2adfb12
Handle capturing of primary constructor parameters within queries and…
AlekseyTs Jan 9, 2023
181c6e2
Refactor GetCapturedParameters method into reusable and parameter spe…
AlekseyTs Jan 10, 2023
919b343
Merge 'dotnet/main' into PrimaryConstructors
AlekseyTs Jan 11, 2023
64339ea
Merge 'dotnet/main' into PrimaryConstructors (#66364)
AlekseyTs Jan 12, 2023
6cd1af5
Adjust closure initialization for primary constructor (#66340)
AlekseyTs Jan 12, 2023
ca37529
Report double storage warning for primary constructor parameters (#66…
AlekseyTs Jan 13, 2023
e2a08b5
Test/implement some aspects of primary constructor parameter capturin…
AlekseyTs Jan 28, 2023
0ef5933
Merge 'dotnet/main' into PrimaryConstructors
AlekseyTs Jan 29, 2023
998488c
Merge 'dotnet/main' into PrimaryConstructors (#66591)
AlekseyTs Jan 30, 2023
0ffa3fa
Test/implement more aspects of primary constructor parameter capturin…
AlekseyTs Feb 2, 2023
5af6535
Add some EE and EnC tests for primary constructors (#66677)
AlekseyTs Feb 6, 2023
7ceec17
Allow `interface_body` and `enum_body` to consist of just a `;`. (#66…
AlekseyTs Feb 8, 2023
a2af422
Handle captured primary constructor parameters in readonly context. (…
AlekseyTs Feb 8, 2023
c61ca2c
Add tests for some "Primary Constructors" IDE scenarios. (#66774)
AlekseyTs Feb 13, 2023
716d89f
Merge remote-tracking branch 'dotnet/main' into PrimaryConstructors_21
AlekseyTs Feb 14, 2023
d5aa258
Follow up on merge from 'main'
AlekseyTs Feb 14, 2023
3771d3a
Merge 'dotnet/main' into PrimaryConstructors (#66866)
AlekseyTs Feb 15, 2023
d91e6b5
Fix IDE behavior and tests for some Primary Constructors scenarios (#…
AlekseyTs Feb 15, 2023
6a40c80
Add some EnC tests for primary constructors (#66897)
AlekseyTs Feb 15, 2023
406350c
Address PROTOTYPE comments for "Primary Constructors" (#66865)
AlekseyTs Feb 16, 2023
cfe9f31
Parse parameter list on an interface in error recovery mode (#66940)
AlekseyTs Feb 21, 2023
461c28c
Disable EnC for more Primary Constructors scenarios (#67026)
AlekseyTs Feb 28, 2023
4e701c6
Merge 'dotnet/main' into PrimaryConstructors
AlekseyTs Feb 28, 2023
cd79be3
Merge 'dotnet/main' into PrimaryConstructors (#67111)
AlekseyTs Mar 1, 2023
e9ceebd
Address remaining PROTOTYPE comments (#67109)
AlekseyTs Mar 1, 2023
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
56 changes: 56 additions & 0 deletions src/Analyzers/CSharp/Tests/AddParameter/AddParameterTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2809,6 +2809,22 @@ public static class IsExternalInit { }
", parseOptions: TestOptions.Regular.WithLanguageVersion(LanguageVersion.CSharp9));
}

[Fact]
public async Task Test_PrimaryConstructor_Class()
{
await TestInRegularAndScriptAsync(@"
var b = ""B"";
var r = [|new R(1, b)|];

class R(int A);
", @"
var b = ""B"";
var r = new R(1, b);

class R(int A, string b);
", parseOptions: TestOptions.Regular.WithLanguageVersion(LanguageVersion.Preview));
}

[Fact, WorkItem(54408, "https://github.com/dotnet/roslyn/issues/54408")]
public async Task TestPositionalRecordStruct()
{
Expand All @@ -2835,6 +2851,22 @@ public static class IsExternalInit { }
", parseOptions: TestOptions.Regular.WithLanguageVersion(LanguageVersion.CSharp9));
}

[Fact]
public async Task Test_PrimaryConstructor_Struct()
{
await TestInRegularAndScriptAsync(@"
var b = ""B"";
var r = [|new R(1, b)|];

struct R(int A);
", @"
var b = ""B"";
var r = new R(1, b);

struct R(int A, string b);
", parseOptions: TestOptions.Regular.WithLanguageVersion(LanguageVersion.Preview));
}

[Fact, WorkItem(56952, "https://github.com/dotnet/roslyn/issues/56952")]
public async Task TestRecordsNamingConventions()
{
Expand All @@ -2847,6 +2879,18 @@ record Test(string V);
");
}

[Fact]
public async Task TestNamingConventions_PrimaryConstructor_Class()
{
await TestInRegularAndScript1Async(@"[|new Test(""repro"")|];

class Test();
", @"new Test(""repro"");

class Test(string v);
");
}

[Fact, WorkItem(56952, "https://github.com/dotnet/roslyn/issues/56952")]
public async Task TestRecordsNamingConventions_RecordStruct()
{
Expand All @@ -2859,6 +2903,18 @@ record struct Test(string V);
");
}

[Fact]
public async Task TestNamingConventions_PrimaryConstructor_Struct()
{
await TestInRegularAndScript1Async(@"[|new Test(""repro"")|];

struct Test();
", @"new Test(""repro"");

struct Test(string v);
");
}

[Fact, WorkItem(61715, "https://github.com/dotnet/roslyn/issues/61715")]
public async Task TestMethodGroup1()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -802,6 +802,52 @@ record R(int [|First|], int Second, int Third);
/// <param name=""Second""></param>
/// <param name=""Third""></param>
record R(int First, int Second, int Third);
";
await TestAsync(initial, expected);
}

[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsAddDocCommentNodes)]
public async Task AddsParamTag_Class()
{
var initial = @"
/// <summary>
///
/// </summary>
/// <param name=""Second""></param>
class R(int [|First|], int Second, int Third);
";

var expected = @"
/// <summary>
///
/// </summary>
/// <param name=""First""></param>
/// <param name=""Second""></param>
/// <param name=""Third""></param>
class R(int First, int Second, int Third);
";
await TestAsync(initial, expected);
}

[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsAddDocCommentNodes)]
public async Task AddsParamTag_Struct()
{
var initial = @"
/// <summary>
///
/// </summary>
/// <param name=""Second""></param>
struct R(int [|First|], int Second, int Third);
";

var expected = @"
/// <summary>
///
/// </summary>
/// <param name=""First""></param>
/// <param name=""Second""></param>
/// <param name=""Third""></param>
struct R(int First, int Second, int Third);
";
await TestAsync(initial, expected);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,16 @@ await TestMissingAsync(
}");
}

[Fact]
public async Task TestMissingWithMutableAndReadOnlyFieldStruct2()
{
await TestMissingAsync(
@"struct S(int j)
{
int i;
}");
}

[Fact]
public async Task TestMissingWithMutableProperty()
{
Expand Down Expand Up @@ -160,6 +170,16 @@ await TestMissingAsync(
}");
}

[Fact]
public async Task TestMissingWithMutablePropertyStruct2()
{
await TestMissingAsync(
@"struct S(int q)
{
int P { get; set; }
}");
}

[Fact]
public async Task TestMissingWithEmptyStruct()
{
Expand All @@ -179,14 +199,23 @@ await TestMissingAsync(
}

[Fact]
public async Task TestMissingWithEmptyStructPrimaryConstructor()
public async Task TestMissingWithEmptyRecordStructPrimaryConstructor()
{
await TestMissingAsync(
@"record struct S()
{
}");
}

[Fact]
public async Task TestMissingWithEmptyStructPrimaryConstructor()
{
await TestMissingAsync(
@"struct S()
{
}");
}

[Fact]
public async Task TestMissingWithOtherReadonlyPartialPart()
{
Expand Down Expand Up @@ -309,6 +338,15 @@ await TestMissingAsync(
}");
}

[Fact]
public async Task TestMissingStructWithPrimaryConstructor()
{
await TestMissingAsync(
@"struct S(int i)
{
}");
}

[Fact]
public async Task TestMissingOnRecordStructWithPrimaryConstructorFieldAndNormalField()
{
Expand All @@ -319,6 +357,21 @@ await TestMissingAsync(
}");
}

[Fact]
public async Task TestOnStructWithPrimaryConstructorAndReadonlyField()
{
await TestAsync(
@"struct [|S|](int i)
{
readonly int i;
}",
@"readonly struct S(int i)
{
readonly int i;
}",
LanguageVersion.Preview);
}

[Fact]
public async Task TestNestedStructs1()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1030,6 +1030,66 @@ public record Base
new CSharpParseOptions(LanguageVersion.CSharp9));
}

[Fact]
public async Task UpgradeProjectForPrimaryConstructors_Class()
{
await TestLanguageVersionUpgradedAsync(
@"
class Program[|()|];",
LanguageVersion.Preview,
new CSharpParseOptions(LanguageVersion.CSharp11));
}

[Fact]
public async Task UpgradeProjectForPrimaryConstructors_Struct()
{
await TestLanguageVersionUpgradedAsync(
@"
struct Program[|()|];",
LanguageVersion.Preview,
new CSharpParseOptions(LanguageVersion.CSharp11));
}

[Fact]
public async Task UpgradeProjectForSemicolonBody_Class()
{
await TestLanguageVersionUpgradedAsync(
@"
class Program[|;|]",
LanguageVersion.Preview,
new CSharpParseOptions(LanguageVersion.CSharp11));
}

[Fact]
public async Task UpgradeProjectForSemicolonBody_Struct()
{
await TestLanguageVersionUpgradedAsync(
@"
struct Program[|;|]",
LanguageVersion.Preview,
new CSharpParseOptions(LanguageVersion.CSharp11));
}

[Fact]
public async Task UpgradeProjectForSemicolonBody_Interface()
{
await TestLanguageVersionUpgradedAsync(
@"
interface Program[|;|]",
LanguageVersion.Preview,
new CSharpParseOptions(LanguageVersion.CSharp11));
}

[Fact]
public async Task UpgradeProjectForSemicolonBody_Enum()
{
await TestLanguageVersionUpgradedAsync(
@"
enum Program[|;|]",
LanguageVersion.Preview,
new CSharpParseOptions(LanguageVersion.CSharp11));
}

[Fact]
public async Task UpgradeProjectForTargetTypedNew()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,17 +98,19 @@ private static void ComputeDeclarations(

return;
}
case SyntaxKind.ClassDeclaration:
case SyntaxKind.StructDeclaration:
case SyntaxKind.RecordDeclaration:
case SyntaxKind.RecordStructDeclaration:
{
if (associatedSymbol is IMethodSymbol ctor)
{
var recordDeclaration = (RecordDeclarationSyntax)node;
Debug.Assert(ctor.MethodKind == MethodKind.Constructor && recordDeclaration.ParameterList is object);
var typeDeclaration = (TypeDeclarationSyntax)node;
Debug.Assert(ctor.MethodKind == MethodKind.Constructor && typeDeclaration.ParameterList is object);

var codeBlocks = GetParameterListInitializersAndAttributes(recordDeclaration.ParameterList);
var codeBlocks = GetParameterListInitializersAndAttributes(typeDeclaration.ParameterList);

if (recordDeclaration.BaseList?.Types.FirstOrDefault() is PrimaryConstructorBaseTypeSyntax initializer)
if (typeDeclaration.BaseList?.Types.FirstOrDefault() is PrimaryConstructorBaseTypeSyntax initializer)
{
codeBlocks = codeBlocks.Concat(initializer);
}
Expand All @@ -117,10 +119,8 @@ private static void ComputeDeclarations(
return;
}

goto case SyntaxKind.ClassDeclaration;
goto case SyntaxKind.InterfaceDeclaration;
}
case SyntaxKind.ClassDeclaration:
case SyntaxKind.StructDeclaration:
case SyntaxKind.InterfaceDeclaration:
{
var t = (TypeDeclarationSyntax)node;
Expand Down
Loading