Skip to content

Commit

Permalink
Fix SyntaxGenerator not working correctly with 'required' (#62945)
Browse files Browse the repository at this point in the history
  • Loading branch information
Youssef1313 authored Aug 8, 2022
1 parent d681d85 commit 2f62c90
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/Workspaces/CSharpTest/CodeGeneration/SyntaxGeneratorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2352,6 +2352,22 @@ public void TestAddFileModifierToPublicClass()
}");
}

[Fact]
public void TestAddRequiredModifierToVirtualProperty()
{
var property = (PropertyDeclarationSyntax)SyntaxFactory.ParseMemberDeclaration("public virtual int P { get; }");
var updatedProperty = Generator.WithModifiers(property, Generator.GetModifiers(property).WithIsRequired(true));
VerifySyntax<PropertyDeclarationSyntax>(updatedProperty, "public virtual required int P { get; }");
}

[Fact]
public void TestAddVirtualModifierToRequiredProperty()
{
var property = (PropertyDeclarationSyntax)SyntaxFactory.ParseMemberDeclaration("public required int P { get; }");
var updatedProperty = Generator.WithModifiers(property, Generator.GetModifiers(property).WithIsVirtual(true));
VerifySyntax<PropertyDeclarationSyntax>(updatedProperty, "public virtual required int P { get; }");
}

[Fact]
public void TestGetType()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ public static void GetAccessibilityAndModifiers(SyntaxTokenList modifierList, ou
SyntaxKind.VolatileKeyword => DeclarationModifiers.Volatile,
SyntaxKind.ExternKeyword => DeclarationModifiers.Extern,
SyntaxKind.FileKeyword => DeclarationModifiers.File,
SyntaxKind.RequiredKeyword => DeclarationModifiers.Required,
_ => DeclarationModifiers.None,
};

Expand Down

0 comments on commit 2f62c90

Please sign in to comment.