Skip to content

Commit

Permalink
Merge pull request #54427 from Youssef1313/add-param-records
Browse files Browse the repository at this point in the history
Fix add parameter for records
  • Loading branch information
CyrusNajmabadi authored Jun 28, 2021
2 parents 48dd54f + 0254fbd commit 3383013
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 0 deletions.
54 changes: 54 additions & 0 deletions src/EditorFeatures/CSharpTest/AddParameter/AddParameterTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2849,5 +2849,59 @@ void Test()
}
}");
}

[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsAddParameter)]
[WorkItem(54408, "https://github.com/dotnet/roslyn/issues/54408")]
public async Task TestPositionalRecord()
{
await TestInRegularAndScriptAsync(@"
var b = ""B"";
var r = [|new R(1, b)|];
record R(int A);
namespace System.Runtime.CompilerServices
{
public static class IsExternalInit { }
}
", @"
var b = ""B"";
var r = new R(1, b);
record R(int A, string b);
namespace System.Runtime.CompilerServices
{
public static class IsExternalInit { }
}
", parseOptions: TestOptions.Regular.WithLanguageVersion(LanguageVersion.CSharp9));
}

[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsAddParameter)]
[WorkItem(54408, "https://github.com/dotnet/roslyn/issues/54408")]
public async Task TestPositionalRecordStruct()
{
await TestInRegularAndScriptAsync(@"
var b = ""B"";
var r = [|new R(1, b)|];
record struct R(int A);
namespace System.Runtime.CompilerServices
{
public static class IsExternalInit { }
}
", @"
var b = ""B"";
var r = new R(1, b);
record struct R(int A, string b);
namespace System.Runtime.CompilerServices
{
public static class IsExternalInit { }
}
", parseOptions: TestOptions.Regular.WithLanguageVersion(LanguageVersion.CSharp9));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2116,6 +2116,9 @@ private static SyntaxNode WithParameterList(SyntaxNode declaration, BaseParamete
.WithLeadingTrivia(lambda.GetLeadingTrivia())
.WithTrailingTrivia(lambda.GetTrailingTrivia());
}
case SyntaxKind.RecordDeclaration:
case SyntaxKind.RecordStructDeclaration:
return ((RecordDeclarationSyntax)declaration).WithParameterList((ParameterListSyntax)list);
default:
return declaration;
}
Expand Down

0 comments on commit 3383013

Please sign in to comment.