-
Notifications
You must be signed in to change notification settings - Fork 217
Add rules to allow omission of certain default values #4393
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: main
Are you sure you want to change the base?
Conversation
I like the general direction here, but if we're going to loosen the proposal so that augmentations can fill in default values, I think we should go all the way and let them do it for all functions. |
I changed the rules to allow all kinds of augmentable functions (incl. constructors) to specify a default value for an optional parameter in the introductory declaration or in an augmentation, but at most once, PTAL! |
@munificent, WDYT? |
4ac903e
to
ae929b8
Compare
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 think we can loosen this up a little more. If you're OK with that, LGTM!
@@ -840,13 +841,21 @@ Augmenting constructors works similar to augmenting a function, with some extra | |||
rules to handle features unique to constructors like redirections and | |||
initializer lists. | |||
|
|||
It is **not** a compile-time error for an incomplete factory constructor to | |||
omit default values. *That is, they are treated similarly to abstract |
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.
This touches on #3690. With augmentations, it's also not a compile error for a static method declaration to have a ;
body, for a constructor declaration to not have initializers are all final instance fields, etc. As long as the final declaration ("definition"?) once all augmentations have been applied is valid, it's fine.
I'm not sure to what degree we want to spell this all out in the proposal but I'm cautious about having too much normative text that is potentially redundant or implied by other parts of the proposal. I don't want implementers to have to read between the lines to figure out what the proposal is saying, but I also don't want them to have to compare paragraphs and try to tell if the two paragraphs are defining different things or just restating a point. Finding the right balance here is hard.
* The augmenting constructor parameters specify any default values. | ||
*Default values are defined solely by the introductory constructor.* | ||
* The augmenting constructor parameters specify any default values, and | ||
the constructor is not a non-redirecting factory. *Default values are |
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.
If we're going to support allowing augmentations to specify default values at all, I don't see why we wouldn't generalize that and allow augmentations of all functions to fill them in. Why restrict this to non-redirecting factory constructors? We have to take the complexity hit either way.
* The augmenting function specifies any default values. *Default values are | ||
defined solely by the introductory function.* | ||
* The augmentation chain has two or more specifications of a default value | ||
for the same optional parameter. This is an error even in the case where |
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 think this might be a little more readable as: "More than one declaration in the augmentation chain specifies a default value for some optional parameter."
all of them are identical. *Default values are defined by the introductory | ||
function or an augmentation, but at most once.* | ||
|
||
* The augmentation chain has no specifications of a default value for an |
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.
Likewise here: "No declaration in the augmentation chain specifies a default value for an..."
declaration or an augmentation, but at most once.* | ||
|
||
* The augmentation chain has exactly one specification of a default value | ||
for an optional parameter, and the constructor is a redirecting factory. |
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.
Is this error needed? This means that if the introductory declaration has a default value, the augmentation is prohibited from filling in a redirectory factory.
How about we just treat default values in redirecting factory constructors the same way we do abstract methods: they are meaningless documentation. You can write it but it won't do anything.
|
||
* A constructor declaration in an augmentation chain is a redirecting | ||
factory, and some declaration in the chain specifies a default value | ||
for one or more parameters. |
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.
See my previous comment. :)
This PR changes the rules about augmentation of constructors such that an incomplete factory is able to defer the decision about implementing the constructor by a redirection or by a body. See #4172 for details.