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

can you adapt an abstract class? #4387

Open
zygoloid opened this issue Oct 8, 2024 · 1 comment
Open

can you adapt an abstract class? #4387

zygoloid opened this issue Oct 8, 2024 · 1 comment
Assignees
Labels
leads question A question for the leads team

Comments

@zygoloid
Copy link
Contributor

zygoloid commented Oct 8, 2024

Summary of issue:

Noticed while reviewing #4381: we are disallowing adapting an abstract class type. It's not clear whether this should be allowed or not; I don't think we've considered this question.

Details:

On the one hand, requiring the adapted type in an adapter to be non-abstract is a little simpler. On the other hand, it seems to be a restriction we don't need: we could allow this and the result would be that the adapter itself is also an abstract class.

Any other information that you want to share?

If we allow it, we open up a larger question: when deriving from an adapter, can you override virtual functions from the adapted class? Is some special syntax needed in order to do so, or does impl fn ... look through the adapter to the adapted type? Because an adapter cannot have virtual functions of its own, there's nowhere else that impl fn could look for the function to override, but looking through the adapter might be piercing an abstraction and we might not want to do that silently.

@josh11b
Copy link
Contributor

josh11b commented Oct 8, 2024

My inclination here is to say yes: we have seen a lot of use cases for the adapter feature, and some of those use cases (for example, using adapters to implement member access) probably should not be restricted. While it made sense to start conservatively, I think it is more valuable to avoid unnecessary restrictions that would make the feature less orthogonal.

Regarding implementing a virtual function: agreed it can't be done in the adapter itself, but it should be allowed in classes derived from the adapter. I don't think special syntax should be required. However if it is not an extending adapter, we might want to require that qualifying the name of the virtual method, since otherwise it wouldn't be found by name lookup.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
leads question A question for the leads team
Projects
None yet
Development

No branches or pull requests

2 participants