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

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

This comment was marked as resolved.

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

Went ahead with the breaking change. I can address any LDM feedback later, I wouldn't like to block on that since it shouldn't have any effect on subsequent PRs of the feature.

public void Event_Definition_CSharp13()
{
UsingDeclaration("""
partial event Action E;
Copy link
Contributor

Choose a reason for hiding this comment

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

I suspect we are in the same position we were in with records, where we can't really prompt for LangVersion with forms like record Rec() { } in old language versions.

I don't recall receiving much in the way of complaints about that, just something to be conscious of.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, I haven't investigated that but I imagine that would require some complicated changes in the parser.

Copy link
Contributor

Choose a reason for hiding this comment

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

You might do it by reporting a special error when a lookup fails for ‘record’ or ‘partial’ when binding a return type.

Copy link
Member Author

Choose a reason for hiding this comment

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

That would work for constructors, not events. I'm also not sure how the diagnostic would work exactly - if it was warning or error, it would be a breaking change even for older langversions. I guess that might be fine, it seems similar to the field breaking change diagnostics.

Copy link
Contributor

Choose a reason for hiding this comment

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

if it was warning or error, it would be a breaking change even for older langversions.

The scenario I am describing is one where an error already occurs, for example, partial is used in a type position, but no such type is in scope.

That would work for constructors, not events

I think events would work by simply parsing the partial modifier for them in any LangVersion, then reporting an error on the declaration.

But, to reiterate, I don't think there is a strong need to do these, it's probably something to only do if it is found to be convenient.

Copy link
Member Author

Choose a reason for hiding this comment

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

The scenario I am describing is one where an error already occurs, for example, partial is used in a type position, but no such type is in scope.

I see, thanks. I'm going to investigate that possibility in a future PR.

I think events would work by simply parsing the partial modifier for them in any LangVersion, then reporting an error on the declaration.

Yes, you're right, that's what actually happens in the next PR I have prepared.

// (5,50): error CS1513: } expected
// System.Console.Write(F().GetType().Name);
Diagnostic(ErrorCode.ERR_RbraceExpected, "").WithLocation(5, 50),
// (6,9): error CS0267: The 'partial' modifier can only appear immediately before 'class', 'record', 'struct', 'interface', or a method or property return type.
Copy link
Member

Choose a reason for hiding this comment

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

or a method or property return type

Should this error message be updated to include event or constructor?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, it will be in the next PR (I already have that locally so I would skip adding a prototype comment for that if that's okay)

@jjonescz jjonescz requested a review from RikkiGibson January 28, 2025 17:09
@jjonescz
Copy link
Member Author

@RikkiGibson for a second review, thanks

// partial event
if (this.PeekToken(1).Kind == SyntaxKind.EventKeyword)
{
return IsFeatureEnabled(MessageID.IDS_FeaturePartialEventsAndConstructors);
Copy link
Contributor

Choose a reason for hiding this comment

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

not to belabor it, but, it wasn't obvious to me why event parsing should be conditional on LangVersion. Maybe it's simpler to just be consistent? Perhaps there is some existing form we are trying to avoid breaking? Feel free to add as an open question for a future PR, if any further investigation/work is found to be needed here.

Copy link
Member Author

@jjonescz jjonescz Jan 29, 2025

Choose a reason for hiding this comment

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

Good point, I did this for consistency but now I realize in parsing we want to avoid being conditional like this whenever possible. I don't think this can break anyone since event is a keyword anywhere (it's not contextual).

@jjonescz jjonescz requested review from cston and RikkiGibson January 29, 2025 14:30
@jjonescz
Copy link
Member Author

@RikkiGibson can you take another look? Thanks.

@jjonescz jjonescz merged commit 8b63d50 into dotnet:features/PartialEventsCtors Jan 30, 2025
28 checks passed
@jjonescz jjonescz deleted the PartialEventsCtors-01-Parsing branch January 30, 2025 01:32
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.

4 participants