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

Add proposal for partial events and constructors #9059

Merged
merged 4 commits into from
Jan 20, 2025

Conversation

jjonescz
Copy link
Member

No description provided.


A defining partial constructor declaration:
- Cannot have a constructor initializer (`: this()` or `: base()`; [§15.11.2][ctor-init]).
- Does not perform any variable initializers ([§15.11.3][ctor-var-init]).
Copy link
Contributor

Choose a reason for hiding this comment

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

I find it a little confusing to actually specify this, it makes me wonder if we give the same precaution about extern constructors.

Copy link
Member Author

Choose a reason for hiding this comment

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

You are right we probably don't need to specify this here, because the spec of variable initializers talks about "instance constructors" which in case of partial ones are composed of a defining and an implementing declaration - so the whole "constructor" will perform the initializers, it doesn't make sense to talk about the partial declarations themselves performing (or not performing) the initializers.

But since you brought this up, to me it seems like the spec has a hole for extern constructors. Right now the spec wording sounds like variable initializers would be executed by extern constructors but they won't be.

Also one can have a class like:

class C
{
    int X = 5;

    extern C();
}

but the initializer is completely ignored by the compiler (it's not emitted anywhere).

Copy link
Contributor

Choose a reason for hiding this comment

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

It is odd. If you wish, you could open an issue on csharpstandard.

Copy link
Member Author

Choose a reason for hiding this comment

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

@jjonescz jjonescz merged commit 293a729 into dotnet:main Jan 20, 2025
1 check passed
@jjonescz jjonescz deleted the PartialEventsCtors branch January 20, 2025 08:27

The attributes of the resulting event or constructor are the combined attributes of the partial declarations.
The attributes of each of the resulting event's accessor
are the combined attributes of the corresponding partial declaration accessors.
Copy link
Member

@cston cston Jan 24, 2025

Choose a reason for hiding this comment

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

are the combined attributes of the corresponding partial declaration accessors

Is it possible to specify attributes for an event accessor on the definition part? If not, perhaps "... is the attributes of the corresponding partial implementation accessors."

The attributes of the resulting event or constructor are the combined attributes of the partial declarations.
The attributes of each of the resulting event's accessor
are the combined attributes of the corresponding partial declaration accessors.
The attributes of each of the resulting constructor's parameter
Copy link
Member

Choose a reason for hiding this comment

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

Perhaps "The attributes of each resulting constructor parameter ..." or "The attributes of each of the resulting constructor's parameters ..." (plural).

Only the defining declaration of a partial member participates in lookup
and is considered at use sites and for emitting the metadata.
(Except for documentation comments as detailed [below](#documentation-comments).)
The implementing declaration signature is used when nullable-analyzing the associated bodies.
Copy link
Member

Choose a reason for hiding this comment

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

when nullable-analyzing

Perhaps "for nullable analysis of".

Otherwise, it is a *defining declaration*.

A partial constructor declaration is said to be a *defining declaration*
when it has the semicolon body and it lacks the `extern` modifier.
Copy link
Member

Choose a reason for hiding this comment

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

the

"a"?

Copy link
Member Author

@jjonescz jjonescz Jan 27, 2025

Choose a reason for hiding this comment

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

I assume you are referring to "the semicolon body", not "the extern modifier" here? I chose "the" because there is only one semicolon body ever (the semicolon), but perhaps that's not the right way to think about it.

Copy link
Member

Choose a reason for hiding this comment

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

Yes, "when it has a semicolon body".

### Attributes

The attributes of the resulting event or constructor are the combined attributes of the partial declarations.
The attributes of each of the resulting event's accessor
Copy link
Member

Choose a reason for hiding this comment

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

Perhaps "The attributes of each resulting event accessor ..." or "The attributes of each of the resulting event's accessors ..." (plural).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants