WARN on implicit super?
Chris Katko
CKATKO at GMAIL.COM
Sun Dec 24 02:34:10 UTC 2017
On Thursday, 21 December 2017 at 10:13:47 UTC, bauss wrote:
> On Thursday, 21 December 2017 at 06:47:25 UTC, Ali Çehreli
> wrote:
>> [...]
>
> This is what I would believe __IS__ and __SHOULD__ be the
> default behavior too, because that's how it generally is in
> other languages.
>
> It doesn't make much sense to call a super constructer after
> and it's very rare cases that you need too.
>
> The only time you really call super constructors after is if
> the parameters are different.
>
> Ex.
>
> class Foo
> {
> int baz;
> int boo;
>
> this() { ... }
>
> this(int baz, int boo) { ... }
> }
>
> class Bar : Foo
> {
> this()
> {
> int baz =getBazFromSomewhere();
> int boo = getBooFromSomewhere();
> super(baz, boo);
> }
> }
>
> In that case it makes sense to call super() after, but you
> rarely end up in cases like that and thus you should generally
> be able to omit the call.
>
> If super() is ever called explicit after (if no call to a super
> constructor has been done.) then I can only imagine A LOT of
> code will break, because it's a general concept and known
> behavior from most languages that base/super constructors are
> called before.
I think during many late night debugging, I had TWO bugs and
confused super call-order and wrote that comment.
What I think happened was, super() was called correctly, but, the
chain of classes was calling this()/super() constructors and
DIDN'T call this(var, var)/super(var,var) constructors that I
needed.
So AFAIK, I'd call this a closed problem / mistaken
understanding. Thanks for your prompt replies and help. Sorry if
I wasted your time.
More information about the Digitalmars-d-learn
mailing list