[BUG] Issues with :this
There are a few issues with doing :base when I was typing it out, I got a crash that relaunch recovered from, later I was backspacing a line and got to ba and the IDE crashed, relaunching also crashed, including ,safe mode, wihch was surprising.
public abstract class Entity : this(float2 position)
{
private static uint64 NextID = 0;
public uint64 ID = ++ID;
public abstract void Update();
public abstract void Render();
}
public class Connection : Entity, this(float2 position, Entity start, Entity end) // start typing :base
{
public override void Update()
{
}
public override void Render()
{
Core.Draw.Line(start.position, end.position, 1f, .White);
}
}
Its also not clear what happens when you do the nested this(float2), I'm gussing the compiler is smart enough to see the field already exists and nothing happens.
A possible enhancement could be that inherited :this could simply prepend the parents arguments to remove the need for :base. So if we dropped position from Connection and then removed the need for :base the ctor would still show float2 position, Entity start, Entity end) sort of like chaining :this. With that said, I wonder if :this should be mandatory and the only ctor allowed since this is all about initialization, so if you needed more initialization you could use a block initializer.
Last but not least, the following code is valid, but I'm not sure it should be acceptable (or perhaps produce a warning). Since Entity now has 2 ctors, you can skip the this(float2 position) in Connection so position is now always zeros. This was an oversight from me because I added :this after remembering they were there and never removed the existing ctor (hence why I think it should be a warning). As I said in the previous paragraph, all of these are why I sort of feel these should be mandatory and the only ctor.
public abstract class Entity : this(float2 position)
{
private static uint64 NextID = 0;
public uint64 ID;
public this()
{
ID = ++NextID;
}
public abstract void Update();
public abstract void Render();
}
public class Connection : Entity, this( Entity start, Entity end)
{
public override void Update()
{
}
public override void Render()
{
}
}
Forgot to add that formatting this document will strip the comma from Entity, this( ... )