-
Notifications
You must be signed in to change notification settings - Fork 424
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
Ambiguity in forwarded vs inherited methods. #10421
Comments
A preview real-world example is here in #10427. |
@mppf: As the person who's spent the most time with forwarding, did you have thoughts about this one? Seems like this is a more interesting question if we imagine having pure virtual functions (where I'm imagining that |
This is very similar to #7786. If we had pure virtual methods, I think it'd be "obvious" that they should be "last resort" and that, as a result, the forwarding method should take precedence over them. That would require some implementation adjustment though (right now, forwarded methods never take precedence over "last resort" methods... but I don't think it'd be so hard check for non-last-resort forwarded methods if there is a "last resort" method.). Do we plan to actually add pure virtual methods any time soon? |
I'd like for us to. I think that there have been lots of recent arguments in favor of them, and few (none?) in opposition. Am I remembering correctly that we thought they could help with some of the hijacking cases you walked us through earlier this year? |
@bradcray - yes, it could help in one case - https://github.com/chapel-lang/chapel/blob/master/doc/rst/developer/chips/20.rst#unexpected-new-overload-for-an-overridden-method - but that case could also be helped by other means (specific errors for certain combinations of override+overload). Anyway I think we have enough methods with a body of "halt" that are meant to be pure virtual that we should do it. Not sure it has an issue yet. |
In the above code, Both DirectlyDerived and MultiDerived inherit from Base, which defines a "virtual method"
mustImplement
. However, MultiDerived also has a DirectlyDerived member variable which it forwards; it does not implementmustImplement
.This compiles fine, but invoking
MultiDerived.useImplement
, in turn invokesBase.mustImplement
instead ofDirectlyDerived.mustImplement
(causing a halt) which may be unexpected.The obvious work-around is to define
MultiDerived.mustImplement
and have it call its member'sDirectlyDerived.mustImplement
method. But this negates (and in this case, entirely negates) the purpose of using forwarding.While it makes sense that subclass-inherited methods take precedence over forward-inherited methods, it would be nice if there was (1) a warning when this happened, and (2) a way to override this behavior (something like
forwarding derived override mustImplement
).The text was updated successfully, but these errors were encountered: