Skip to content

Conversation

@BillWagner BillWagner force-pushed the v9-more-partial-methods branch from 5e7986c to 9e0a0f2 Compare November 11, 2025 21:33
@RexJaeschke RexJaeschke added this to the C# 9.0 milestone Nov 12, 2025
@RexJaeschke RexJaeschke added type: feature This issue describes a new feature Review: pending Proposal is available for review labels Nov 12, 2025
@RexJaeschke RexJaeschke changed the title [Version 9.0] More partial methods [Version 9.0] Feature support for more partial methods Nov 14, 2025
@BillWagner BillWagner force-pushed the v9-more-partial-methods branch from 9e0a0f2 to 13eca45 Compare January 8, 2026 21:28
@BillWagner BillWagner added the meeting: discuss This issue should be discussed at the next TC49-TG2 meeting label Jan 9, 2026
@BillWagner
Copy link
Member Author

BillWagner commented Jan 9, 2026

This is ready for a first look from the committee.

I addressed all the comments from #991. However, #991 (comment) is an instance where the spec language is correct, and the roslyn implementation has a parsing error. See dotnet/roslyn#81947.

Secondly, I made more substantial edits to the original PR. The draft retained a single clause for Partial methods. Looking ahead at the future versions (for the standard), I split this into three sections: General, restricted partial methods, and unrestricted partial methods. I think that makes the text easier to read, and provides the framework for future versions where there are more unrestricted partial methods.

Discussion question: I used the terms in the current PR of "restricted" and "unrestricted". I'm not convinced those are the best terms. It might be better to use "optional partial methods", and "required partial methods", respectively. I'm not sold on those either. Other thoughts?

@BillWagner BillWagner marked this pull request as ready for review January 9, 2026 16:34
In *method_declaration*, the identifier `partial` is recognized as a contextual keyword ([§6.4.4](lexical-structure.md#644-keywords)) only if it immediately precedes the *return_type*. A partial method cannot explicitly implement interface methods.
There are two kinds of partial method declarations: If the body of the method declaration is a semicolon, the declaration is said to be a ***defining partial method declaration***. If the body is other than a semicolon, the declaration is said to be an ***implementing partial method declaration***. Across the parts of a type declaration, there shall be only one defining partial method declaration with a given signature, and there shall be at most only one implementing partial method declaration with a given signature. If an implementing partial method declaration is given, a corresponding defining partial method declaration shall exist, and the declarations shall match as specified in the following:
There are classifications of a partial method declaration:
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
There are classifications of a partial method declaration:
Partial method declarations are classified as follows:

(Or something else - I'm just not keen on the current wording.)

- A method with an *expression-body* or a *block-body* or is declared with the `extern` modifier is said to be an ***implementing partial method declaration***.
- Otherwise, a method declaration where the body of the method declaration is a semicolon is said to be a ***defining partial method declaration***.
Across the parts of a type declaration, there shall be exactly one defining partial method declaration with a given signature. For an implementing partial method declaration is given, a corresponding defining partial method declaration shall exist, and the declarations shall match as specified in the following:
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
Across the parts of a type declaration, there shall be exactly one defining partial method declaration with a given signature. For an implementing partial method declaration is given, a corresponding defining partial method declaration shall exist, and the declarations shall match as specified in the following:
Across the parts of a type declaration, there shall be exactly one defining partial method declaration with a given signature. If an implementing partial method declaration is given, a corresponding defining partial method declaration shall exist, and the declarations shall match as specified in the following:

- The declarations shall have the same method name, number of type parameters, and number of parameters.
- The declarations shall have the same modifiers except for the `async` and `extern` modifiers. The `async` and `extern` modifiers are allowed only on the implementing partial method declaration.
- Corresponding parameters in the declarations shall have the same modifiers (although not necessarily in the same order) and the same types (modulo differences in type parameter names).
Copy link
Contributor

Choose a reason for hiding this comment

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

Not sure about the type parameter names - do we have an example of this?

I can't remember what we say elsewhere about tuple types and "sameness" - is it valid to have:

partial void M((int x, string y) tuple);

partial void M((int a, string b) otherTuple) { ... }

?

- Corresponding type parameters in the declarations shall have the same constraints (modulo differences in type parameter names).
An implementing partial method declaration can appear in the same part as the corresponding defining partial method declaration.
There are two versions of partial methods: restricted and unrestricted. A ***restricted partial method*** (§restricted-partial-methods) has no explicit access modifiers, and is implicitly private. An ***unrestricted partial method*** (§unrestricted-partial-methods) is a partial method that includes one or more explicit access modifiers.
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd prefer to avoid the word "version" here. Maybe this is another "classification" (as well as defining/implementing)?

- The `partial` modifier is not included.
- All modifiers except the `partial` modifier are included in the resulting, including any `extern` or `async` modifier declared on the implementing declaration.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
- All modifiers except the `partial` modifier are included in the resulting, including any `extern` or `async` modifier declared on the implementing declaration.
- All modifiers except the `partial` modifier are included in the resulting method declaration, including any `extern` or `async` modifier declared on the implementing declaration.

Separately, it's not clear to me what the impact of this is.

Across the parts of a type declaration, there shall be exactly one defining partial method declaration with a given signature. For an implementing partial method declaration is given, a corresponding defining partial method declaration shall exist, and the declarations shall match as specified in the following:
- The declarations shall have the same method name, number of type parameters, and number of parameters.
- The declarations shall have the same modifiers except for the `async` and `extern` modifiers. The `async` and `extern` modifiers are allowed only on the implementing partial method declaration.
Copy link
Contributor

Choose a reason for hiding this comment

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

How about readonly? I think it would make sense for an implementation to potentially be readonly even if the declaration isn't - and in that case, I'd expect the readonly-ness to be available elsewhere in the code.


#### §unrestricted-partial-methods Unrestricted partial methods

An unrestriced partial method declartion incluces an explicit access modifier. There shall be exactly one implementing partial method declaration.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
An unrestriced partial method declartion incluces an explicit access modifier. There shall be exactly one implementing partial method declaration.
An unrestricted partial method declaration incluces an explicit access modifier. There shall be exactly one implementing partial method declaration.

RexJaeschke and others added 3 commits January 16, 2026 11:09
fix md formatting

revert to previous text

handle imp/exp private

allow partial with ref_kind returns

change link's target name
Also, edit after moving text around.
Clean up a bit of language and flow.
@BillWagner BillWagner force-pushed the v9-more-partial-methods branch from df85388 to 5839c04 Compare January 16, 2026 16:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

meeting: discuss This issue should be discussed at the next TC49-TG2 meeting Review: pending Proposal is available for review type: feature This issue describes a new feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants