-
Notifications
You must be signed in to change notification settings - Fork 205
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 an error and adjust the terminology slightly about augmented redirecting constructors #4157
base: main
Are you sure you want to change the base?
Conversation
|
||
This converts it into a redirecting generative constructor, removing the | ||
potentially non-redirecting property of the constructor. | ||
|
||
It is a compile-time error if: | ||
|
||
* The augmented constructor has any initializers or a body. | ||
* The augmented constructor has an initializer list or a body, or it has a | ||
redirection. |
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 assume this error was intended: "adds its redirection" sounds like the redirection position isn't currently occupied, otherwise we would say something like "adds its redirection or replaces the existing one". Also, the implied statement that the augmented constructor is potentially non-redirecting would not be true if it is already a redirecting generative constructor. Finally, it's an error to do the same thing with a super-initializer:
class A {
A(int _);
}
class B extends A {
B(): super(1);
augment B(): super(2); // Error.
}
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.
Commented on two changes.
@@ -945,7 +947,7 @@ constructor. | |||
|
|||
It is a compile-time error if: | |||
|
|||
* The augmented constructor has a body. | |||
* The augmented factory constructor has a body, or it is redirecting. |
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.
Similar to the generative redirecting case.
This PR introduces an error for the case where a redirection (
this(...)
) is augmented by another redirection, and similarly for a redirecting factory.This follows the treatment of super-initializers, for which it is also an error to include one in an augmenting declaration if the augmented declaration already has an explicitly declared super-initializer.
Other than that, it clarifies the terminology of the augmentation feature specification slightly, such that we keep
this(...)
andthis.x = 42
clearly separated.'redirecting initializer' is changed to 'redirection' when talking about generative redirecting constructors. The term is derived from
<redirection>
, and the word redirection is used in other specification documents about this kind of term. This also helps avoiding the confusion aboutthis(...)
possibly being an initializer list element (likex = 42
orassert(b)
).I also added a few words of commentary right after the phrase 'factory redirection' because this phrase is new (the grammar rule actually doesn't have a separate name for the token sequence covered by this phrase). Finally, I deleted a TODO comment which is obsolete today (there are no special grammar rules about
augmented
).