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 an error and adjust the terminology slightly about augmented redirecting constructors #4157

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

eernstg
Copy link
Member

@eernstg eernstg commented Nov 7, 2024

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(...) and this.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 about this(...) possibly being an initializer list element (like x = 42 or assert(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).

@eernstg eernstg changed the title Adjust the terminology slightly about augmented redirecting constructors Add an error and adjust the terminology slightly about augmented redirecting constructors Nov 7, 2024

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.
Copy link
Member Author

@eernstg eernstg Nov 7, 2024

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.
}

Copy link
Member Author

@eernstg eernstg left a 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.

working/augmentation-libraries/feature-specification.md Outdated Show resolved Hide resolved
@@ -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.
Copy link
Member Author

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.

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.

1 participant