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
Open
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions working/augmentation-libraries/feature-specification.md
Original file line number Diff line number Diff line change
Expand Up @@ -855,8 +855,9 @@ It is a compile-time error if:
replace a declared super constructor._ **(TODO: Why not? We allow
"replacing implementation", and this is *something* like that.)**

* The resulting constructor is not valid (has a redirecting initializer and
other initializers, multiple `super` initializers, etc).
* The resulting constructor is not valid *(it has a redirection as well as
some initializer list elements, or it has multiple `super` initializers,
etc)*.

* A non-redirecting constructor augments a constructor which is not
potentially non-redirecting.
Expand Down Expand Up @@ -923,20 +924,21 @@ present), and it may invoke the augmented body by calling

#### Redirecting generative constructors

A redirecting generative constructor marked `augment` adds its redirecting
initializer to the augmented constructors initializer list.
A redirecting generative constructor marked `augment` adds its redirection
to the augmented constructor.

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


#### Redirecting factory constructors

A redirecting factory constructor marked `augment` adds its factory redirection
to the augmented constructor.
*(e.g., `= C<int>.name`)* to the augmented constructor.

The result of applying the augmenting constructor is a redirecting factory
constructor with the same target constructor designation as the augmenting
Expand All @@ -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.

#### Extension types

Expand Down Expand Up @@ -1201,8 +1203,6 @@ declaration ::= 'external'? factoryConstructorSignature
| constructorSignature (redirection | initializers)?
```

**TODO: Define the grammar for the various `augmented` expressions.**

It is a compile-time error if:

* A declaration marked `augment` is also marked `external`. **(TODO: Probably
Expand Down