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 rules about super and extension types to wildcard spec #3729

Merged
merged 4 commits into from
Apr 30, 2024

Conversation

eernstg
Copy link
Member

@eernstg eernstg commented Apr 26, 2024

This PR adds rules to the wildcards feature specification about super parameters of the form super._, and about representation declarations in extension types whose representation variable name is _.

In particular, super._ is an error because super parameters that can't be referenced from the initializer list are inherently broken. In contrast, extension type E(int _) {} is allowed: The representation variable name will be _ and the formal parameter will be inaccessible (which makes no difference at this time, but will matter if a more general primary constructors feature is introduced).

@eernstg eernstg requested review from munificent and kallentu April 26, 2024 14:40
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.

Added a few explanatory remarks.

working/wildcards/feature-specification.md Show resolved Hide resolved
working/wildcards/feature-specification.md Show resolved Hide resolved
working/wildcards/feature-specification.md Show resolved Hide resolved
Copy link
Member

@munificent munificent left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks great, thank you! And thank you for the explanatory commentary too, it was very helpful.

working/wildcards/feature-specification.md Show resolved Hide resolved
working/wildcards/feature-specification.md Show resolved Hide resolved
*The desugared meaning of a super parameter includes a reference to the
parameter in the initializer list of the enclosing constructor declaration,
but such references are not possible when the parameter name is a
wildcard.*
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a funny subtle point, but made sense once I thought about it some more.

Copy link
Member

@kallentu kallentu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is great! Thank you so much for updating the spec, Erik!

working/wildcards/feature-specification.md Show resolved Hide resolved
working/wildcards/feature-specification.md Outdated Show resolved Hide resolved
### Super parameters

An occurrence of `super._` as a declaration of a formal parameter in a
constructor is a compile-time error.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you also help me visualize this, and maybe the following below, by adding a little code snippet/example?
The words make sense, I just learn better with examples.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. This brings out a slight inconvenience, by the way. I added a commentary paragraph about it.

working/wildcards/feature-specification.md Show resolved Hide resolved
working/wildcards/feature-specification.md Outdated Show resolved Hide resolved
@eernstg
Copy link
Member Author

eernstg commented Apr 30, 2024

@kallentu, we might want to delete the 20 lines just before 'Unused variable warnings', PTAL.

@kallentu
Copy link
Member

@kallentu, we might want to delete the 20 lines just before 'Unused variable warnings', PTAL.

I would be okay with that. It might be more confusing with that example haha, but thank you for writing it up.

@eernstg
Copy link
Member Author

eernstg commented Apr 30, 2024

OK, done!

@eernstg eernstg merged commit d925d1f into main Apr 30, 2024
3 checks passed
@eernstg eernstg deleted the spec_wildcards_primary_constructors_apr24 branch April 30, 2024 18:37
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.

3 participants