Skip to content
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

Open
wants to merge 3 commits into
base: features/PartialEventsCtors
Choose a base branch
from

Conversation

jjonescz
Copy link
Member

Test plan: #76859

@dotnet-issue-labeler dotnet-issue-labeler bot added the untriaged Issues and PRs which have not yet been triaged by a lead label Jan 22, 2025
@jjonescz jjonescz force-pushed the PartialEventsCtors-01-Parsing branch from 91ccc2a to ba8ca9d Compare January 22, 2025 16:09
@jjonescz jjonescz changed the base branch from main to features/PartialEventsCtors January 22, 2025 16:10
@RikkiGibson
Copy link
Contributor

Be sure to include the new feature in https://github.com/dotnet/roslyn/blob/main/docs/Language%20Feature%20Status.md

@@ -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))
Copy link
Member

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?

@@ -1632,26 +1632,28 @@ private bool IsPartialType()
return false;
}

private bool IsPartialMember()
private bool IsPartialMember(bool allowPartialCtor)
Copy link
Member

Choose a reason for hiding this comment

The 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.

Copy link
Member Author

Choose a reason for hiding this comment

The 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;

this.PeekToken(2).Kind == SyntaxKind.OpenParenToken)
{
return true;
}
Copy link
Member

Choose a reason for hiding this comment

The 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?

{
if (this.CurrentToken.ContextualKind == SyntaxKind.PartialKeyword)
{
if (this.IsPartialType() || this.IsPartialMember())
if (this.IsPartialType() || this.IsPartialMember(allowPartialCtor: false))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

doc why partial cosntructors are not allowd here.

Copy link
Member

@CyrusNajmabadi CyrusNajmabadi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done with pass.

@jjonescz jjonescz marked this pull request as ready for review January 23, 2025 13:11
@jjonescz jjonescz requested review from a team as code owners January 23, 2025 13:11
@CyrusNajmabadi
Copy link
Member

We should bring to ldm if we can just make partial a keyword in the next version. Like we've done for many other cases at this point. There's a simple workaround (using @partial).

@jjonescz
Copy link
Member Author

We should bring to ldm if we can just make partial a keyword in the next version. Like we've done for many other cases at this point. There's a simple workaround (using @partial).

Sounds good to me. Added the question: dotnet/csharplang#9085

@RikkiGibson RikkiGibson self-assigned this Jan 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Compilers Feature - Partial Events and Constructors untriaged Issues and PRs which have not yet been triaged by a lead
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants