-
Notifications
You must be signed in to change notification settings - Fork 92
[Version 9.0] Feature support for more partial methods #1468
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
base: draft-v9
Are you sure you want to change the base?
Conversation
5e7986c to
9e0a0f2
Compare
9e0a0f2 to
13eca45
Compare
|
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? |
| 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: |
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.
| 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: |
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.
| 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). |
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.
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. |
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.
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. |
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.
| - 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. |
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.
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. |
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.
| 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. |
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.
df85388 to
5839c04
Compare
This PR replaces #991
There are several unaddressed comments on #991: