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

Explicitly invoking super.__ctor in a constructor does not count as calling a super constructor #17860

Open
dlangBugzillaToGithub opened this issue May 20, 2018 · 6 comments

Comments

@dlangBugzillaToGithub
Copy link

Ethan Watson reported this on 2018-05-20T17:20:39Z

Transferred from https://issues.dlang.org/show_bug.cgi?id=18886

CC List

  • Andrei Alexandrescu (@andralex)
  • Adam D. Ruppe
  • RazvanN

Description

Example code at https://run.dlang.io/is/Is9tAs

A workaround is to define a default constructor, as per https://run.dlang.io/is/mhM24Y

But this is just doubling up on work that I shouldn't need to do.

Came about because I was trying to explicitly invoke a templated constructor in a base class. Simple example at https://run.dlang.io/is/XAsoyo
@dlangBugzillaToGithub
Copy link
Author

andrei (@andralex) commented on 2018-06-07T20:16:51Z

This isn't a bug. Calling __ctor explicitly is advanced usage, not part of the usual typechecking. Is there any strong reason to keep this open? Is it preventing some use case?

@dlangBugzillaToGithub
Copy link
Author

destructionator commented on 2018-06-07T20:22:22Z

The templated constructor use case looks valid, but the language doesn't allow you to explicitly call `super!(args)`...

@dlangBugzillaToGithub
Copy link
Author

andrei (@andralex) commented on 2018-06-07T20:23:17Z

Then we should allow that call.

@dlangBugzillaToGithub
Copy link
Author

destructionator commented on 2018-06-07T20:25:34Z

yeah i agree.

@dlangBugzillaToGithub
Copy link
Author

destructionator commented on 2018-06-07T20:26:10Z

errr and also while we're at it, perhaps calling `this!(args)` as well, for forwarding to another ctor in the same class.

@dlangBugzillaToGithub
Copy link
Author

gooberman commented on 2018-06-07T21:09:00Z

The code I'm invoking in my current codebase extracts type data from the template parameter for object management.

Another workaround would probably be to have a templated this( Type )( ref Type val ) in the base class and then call super( this ) from the derived class. Which feels as janky as it looks.

Supporting super!( Args )() would be far more preferable, won't even need to do a __ctor hack then.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant