-
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
Parse partial events and constructors #76860
base: features/PartialEventsCtors
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1379,7 +1379,7 @@ private void ParseModifiers(SyntaxListBuilder tokens, bool forAccessors, bool fo | |
{ | ||
case DeclarationModifiers.Partial: | ||
var nextToken = PeekToken(1); | ||
if (this.IsPartialType() || this.IsPartialMember()) | ||
if (this.IsPartialType() || this.IsPartialMember(allowPartialCtor: !forTopLevelStatements)) | ||
{ | ||
// Standard legal cases. | ||
modTok = ConvertToKeyword(this.EatToken()); | ||
|
@@ -1632,26 +1632,28 @@ private bool IsPartialType() | |
return false; | ||
} | ||
|
||
private bool IsPartialMember() | ||
private bool IsPartialMember(bool allowPartialCtor) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. my preference is to not have ambient state. that makes parsing (esp. incremental parsing) more difficult. Is it possible to just answer this uniformly regardless on ambient state? It might mean parsing something out which needs a binding error later, but that's fine. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't like that either, but I need to avoid breaks in cases like this: System.Console.Write(F().GetType().Name);
partial F() => new(); // don't want to parse this as a constructor in top-level statements
class @partial; |
||
{ | ||
// note(cyrusn): this could have been written like so: | ||
// | ||
// return | ||
// this.CurrentToken.ContextualKind == SyntaxKind.PartialKeyword && | ||
// this.PeekToken(1).Kind == SyntaxKind.VoidKeyword; | ||
// | ||
// However, we want to be lenient and allow the user to write | ||
// 'partial' in most modifier lists. We will then provide them with | ||
// a more specific message later in binding that they are doing | ||
// something wrong. | ||
// | ||
// Some might argue that the simple check would suffice. | ||
// However, we'd like to maintain behavior with | ||
// previously shipped versions, and so we're keeping this code. | ||
Debug.Assert(this.CurrentToken.ContextualKind == SyntaxKind.PartialKeyword); | ||
|
||
// Check for: | ||
// partial event | ||
if (this.PeekToken(1).Kind == SyntaxKind.EventKeyword) | ||
{ | ||
return true; | ||
} | ||
|
||
// Here we check for: | ||
// Check for constructor: | ||
// partial Identifier( | ||
if (allowPartialCtor && | ||
this.PeekToken(1).Kind == SyntaxKind.IdentifierToken && | ||
this.PeekToken(2).Kind == SyntaxKind.OpenParenToken) | ||
{ | ||
return true; | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. my preference is to always return true here. Why would we not want that? |
||
|
||
// Check for method/property: | ||
// partial ReturnType MemberName | ||
Debug.Assert(this.CurrentToken.ContextualKind == SyntaxKind.PartialKeyword); | ||
using var _ = this.GetDisposableResetPoint(resetOnDispose: true); | ||
|
||
this.EatToken(); // partial | ||
|
@@ -5680,7 +5682,7 @@ private bool IsTrueIdentifier() | |
{ | ||
if (this.CurrentToken.Kind == SyntaxKind.IdentifierToken) | ||
{ | ||
if (!IsCurrentTokenPartialKeywordOfPartialMethodOrType() && | ||
if (!IsCurrentTokenPartialKeywordOfPartialMemberOrType() && | ||
!IsCurrentTokenQueryKeywordInQuery() && | ||
!IsCurrentTokenWhereOfConstraintClause()) | ||
{ | ||
|
@@ -5727,7 +5729,7 @@ private SyntaxToken ParseIdentifierToken(ErrorCode code = ErrorCode.ERR_Identifi | |
// show the correct parameter help in this case. So, when we see "partial" we check if it's being used | ||
// as an identifier or as a contextual keyword. If it's the latter then we bail out. See | ||
// Bug: vswhidbey/542125 | ||
if (IsCurrentTokenPartialKeywordOfPartialMethodOrType() || IsCurrentTokenQueryKeywordInQuery()) | ||
if (IsCurrentTokenPartialKeywordOfPartialMemberOrType() || IsCurrentTokenQueryKeywordInQuery()) | ||
{ | ||
var result = CreateMissingIdentifierToken(); | ||
result = this.AddError(result, ErrorCode.ERR_InvalidExprTerm, this.CurrentToken.Text); | ||
|
@@ -5754,11 +5756,11 @@ private bool IsCurrentTokenQueryKeywordInQuery() | |
return this.IsInQuery && this.IsCurrentTokenQueryContextualKeyword; | ||
} | ||
|
||
private bool IsCurrentTokenPartialKeywordOfPartialMethodOrType() | ||
private bool IsCurrentTokenPartialKeywordOfPartialMemberOrType() | ||
{ | ||
if (this.CurrentToken.ContextualKind == SyntaxKind.PartialKeyword) | ||
{ | ||
if (this.IsPartialType() || this.IsPartialMember()) | ||
if (this.IsPartialType() || this.IsPartialMember(allowPartialCtor: false)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. doc why partial cosntructors are not allowd here. |
||
{ | ||
return 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.
document. why is this gated on that?