Skip to content

Commit

Permalink
Fix #82
Browse files Browse the repository at this point in the history
For records need to pick an overload that passes SyntaxKind
  • Loading branch information
KirillOsenkov committed Sep 15, 2023
1 parent 003d097 commit 72bdd09
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
19 changes: 19 additions & 0 deletions src/Quoter.Tests/Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -848,6 +848,25 @@ public void TestBinaryLiteral()
Test("0b_0010_1010", NodeKind.Expression);
}

[Fact]
public void TestRecordStruct()
{
Test("record struct A();",
@"RecordDeclaration(
SyntaxKind.RecordStructDeclaration,
Token(SyntaxKind.RecordKeyword),
Identifier(""A""))
.WithClassOrStructKeyword(
Token(SyntaxKind.StructKeyword))
.WithParameterList(
ParameterList())
.WithSemicolonToken(
Token(SyntaxKind.SemicolonToken))
.NormalizeWhitespace()",
shortenCodeWithUsingStatic: true,
nodeKind: NodeKind.MemberDeclaration);
}

private void Test(
string sourceText,
string expected,
Expand Down
10 changes: 9 additions & 1 deletion src/Quoter/Quoter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -239,14 +239,15 @@ node is ClassOrStructConstraintSyntax ||
node is CheckedExpressionSyntax ||
node is CheckedStatementSyntax ||
node is ConstructorInitializerSyntax ||
node is DocumentationCommentTriviaSyntax ||
node is GotoStatementSyntax ||
node is InitializerExpressionSyntax ||
node is LiteralExpressionSyntax ||
node is MemberAccessExpressionSyntax ||
node is OrderingSyntax ||
node is PostfixUnaryExpressionSyntax ||
node is PrefixUnaryExpressionSyntax ||
node is DocumentationCommentTriviaSyntax ||
node is RecordDeclarationSyntax ||
node is YieldStatementSyntax)
{
result.Add(new ApiCall("Kind", "SyntaxKind." + node.Kind().ToString()));
Expand Down Expand Up @@ -1079,6 +1080,13 @@ private MethodInfo PickFactoryMethodToCreateNode(SyntaxNode node)
}
}

if (node is RecordDeclarationSyntax)
{
// for records, pick the overload that specifies the SyntaxKind,
// see https://github.com/KirillOsenkov/RoslynQuoter/issues/82
minParameterCount = 3;
}

MethodInfo factory = null;

if ((node is BaseTypeDeclarationSyntax ||
Expand Down

0 comments on commit 72bdd09

Please sign in to comment.