Bug 18886 – Explicitly invoking super.__ctor in a constructor does not count as calling a super constructor

Status
NEW
Severity
enhancement
Priority
P4
Component
dmd
Product
D
Version
D2
Platform
x86
OS
Windows
Creation time
2018-05-20T17:20:39Z
Last change time
2024-12-13T18:58:49Z
Assigned to
No Owner
Creator
Ethan Watson
Moved to GitHub: dmd#17860 →

Comments

Comment #0 by gooberman — 2018-05-20T17:20:39Z
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
Comment #1 by andrei — 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?
Comment #2 by destructionator — 2018-06-07T20:22:22Z
The templated constructor use case looks valid, but the language doesn't allow you to explicitly call `super!(args)`...
Comment #3 by andrei — 2018-06-07T20:23:17Z
Then we should allow that call.
Comment #4 by destructionator — 2018-06-07T20:25:34Z
yeah i agree.
Comment #5 by destructionator — 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.
Comment #6 by gooberman — 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.
Comment #7 by robert.schadek — 2024-12-13T18:58:49Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/17860 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB