View previous topic :: View next topic |
Author |
Message |
randomZ
Joined: 04 Dec 2004 Posts: 31 Location: Tuebingen, Germany
|
Posted: Mon Oct 08, 2007 4:37 am Post subject: Inheritance: Constructor bug |
|
|
Hi,
I ran into something I think is faulty behaviour. Consider this small module:
Code: | module test;
class A
{
this()
{
writefln("A ctor");
}
}
class B : A
{
this()
{
writefln("B ctor");
super();
}
}
class C : B
{
this()
{
writefln("C ctor");
super();
}
}
local c = C(); |
This code will endlessly repeat the B constructor, never calling the A constructor.
Is there a possibility to have this behaviour fixed? It's quite critical for my project. Or am I just not getting the MiniD semantics right?
Other than that, thanks for MiniD. I had always been afraid of scripting before I found it... it's very easy to integrate and works like a charm.
Thanks
Sebastian |
|
Back to top |
|
|
JarrettBillingsley
Joined: 20 Jun 2006 Posts: 457 Location: Pennsylvania!
|
Posted: Mon Oct 08, 2007 7:39 am Post subject: |
|
|
Oh, my, that is an issue. I think I can fix it. Basically it's working "correctly", at least as far as the way MiniD figures out the base class's constructor. But I guess that way is not quite right..
Until I release a fix, you can use the following. Basically, replace all calls to "super(...)" with "Class.super.constructor(with this, ...)", where Class is the current class.
Code: | class A
{
this()
{
writefln("A ctor");
}
}
class B : A
{
this()
{
writefln("B ctor");
B.super.constructor(with this);
}
}
class C : B
{
this()
{
writefln("C ctor");
C.super.constructor(with this);
}
}
local c = C(); |
This issue also seems to affect super method calls as well, so I hope to have this fixed very soon. |
|
Back to top |
|
|
JarrettBillingsley
Joined: 20 Jun 2006 Posts: 457 Location: Pennsylvania!
|
Posted: Mon Oct 08, 2007 10:27 am Post subject: |
|
|
Aaand it's fixed. Grab the /tags/oct8-2007-1.1 repo. |
|
Back to top |
|
|
randomZ
Joined: 04 Dec 2004 Posts: 31 Location: Tuebingen, Germany
|
Posted: Tue Oct 09, 2007 4:58 am Post subject: |
|
|
Whoa, that was quick. Thanks, I'll give it a try later today. |
|
Back to top |
|
|
|