-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
Implement parsing changes for Primary Constructors feature #65720
Implement parsing changes for Primary Constructors feature #65720
Conversation
For classes and structures: - Support parameters - Support base arguments - Support semicolon as body https://github.com/dotnet/csharplang/blob/main/proposals/primary-constructors.md#syntax
@dotnet/roslyn-compiler Please review. |
@@ -3355,7 +3355,7 @@ | |||
</PropertyComment> | |||
</Field> | |||
</AbstractNode> | |||
<Node Name="ClassDeclarationSyntax" Base="TypeDeclarationSyntax"> | |||
<Node Name="ClassDeclarationSyntax" Base="TypeDeclarationSyntax" SkipConvenienceFactories="true"> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what's the impact of SkipConvenienceFactories? #Resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what's the impact of SkipConvenienceFactories?
Responded at location that illustrates the impact. See #65720 (comment)
} | ||
|
||
/// <summary>Creates a new ClassDeclarationSyntax instance.</summary> | ||
public static ClassDeclarationSyntax ClassDeclaration(SyntaxList<AttributeListSyntax> attributeLists, SyntaxTokenList modifiers, SyntaxToken identifier, TypeParameterListSyntax? typeParameterList, BaseListSyntax? baseList, SyntaxList<TypeParameterConstraintClauseSyntax> constraintClauses, SyntaxList<MemberDeclarationSyntax> members) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what's the impact of SkipConvenienceFactories?
Generator stops auto generating these three factories. Since braces become optional, generated implementation starts using default
for for them. And these factories stop producing syntactically valid nodes. I moved them with original implementation to SyntaxFactory.cs. We no longer rely on generator to generate them.
The same goes for three similar factories for structures below. #Resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Got it. Thanks for the explanation!
var identifier = this.ParseIdentifierToken(); | ||
SyntaxToken identifier; | ||
|
||
if (this.CurrentToken.Kind == SyntaxKind.IdentifierToken && IsCurrentTokenWhereOfConstraintClause()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this an error recovery scenario that is specific to class and struct or could we get here with record too?
This recovery is not specific to any particular type declaration.
Are we testing the record case?
No. Do you think we have to?
public void Class_ParameterListAfterGenericTypeParameters_01(bool @struct) | ||
{ | ||
var text = @" | ||
" + (@struct ? "struct" : "class") + @" C<T>(T x);"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
var text = @" | ||
" + (@struct ? "struct" : "class") + @" C | ||
<T, | ||
(T x);"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider testing class C<T>();
, class C<>;
, class C<>();
#Resolved
@jjonescz, @dotnet/roslyn-compiler For the second review |
For classes and structures:
https://github.com/dotnet/csharplang/blob/main/proposals/primary-constructors.md#syntax