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

Making redeclare a language feature? #4101

Open
bwilkerson opened this issue Sep 23, 2024 · 1 comment
Open

Making redeclare a language feature? #4101

bwilkerson opened this issue Sep 23, 2024 · 1 comment
Labels
question Further information is requested

Comments

@bwilkerson
Copy link
Member

If we were to accept the proposal to make override a language feature, would we also want to make the redeclare annotation a language feature? It serves a similar function, but for extension types.

@bwilkerson bwilkerson added the question Further information is requested label Sep 23, 2024
@lrhn
Copy link
Member

lrhn commented Sep 23, 2024

I would not add redeclare as a language feature.

The override has the effect of documenting intent, making it clear that something is intended to override an existing member, that it is the same virtual member, and that it has an existing signature to satisfy. Someone calling the overridden function at a supertype will get this overriding implementation. Also, because of the explicit link to the superinterface signature, you can get extra benefits in the overriding member (like type inheritance).

The redeclare doesn't have a signature to satisfy, and the method is not accessible to someone trying to call the redeclared member on a supertype. It's an unrelated member with the same name.
The means it's not so much showing intent to be the same thing, as it acknowledging that two unrelated things have the same type, and one is shadowing another. With extension methods and extension type methods, you get what you ask for. (Why are those not both affected by @redeclare?)

The "don't redeclare" lint is not a lint I'd personally enable, and therefore not an annotation I'd use, so it's not surprising that I don't think it carries its own weight as a language feature. Others may disagree.

@lrhn lrhn changed the title Making override a language feature Making redeclare a language feature? Sep 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants