I have just implemented dynamic cast.
Or rather I have debugged it.
The generated byte-code for dynamic cast itself was correct.
However per function only one dynamic cast would be generated.
To generate my dynamic casts I loop through my type table and
look for classes which are dynamic cast targets.
bool needDynamicCast(BCType type)
if (dc.targetType == type)
what follows is the simplified definition of BCType at the point
of the bug
u32, i32, Class, Ptr, Struct, Void;
alias kind this;
Because the members exposed by alias this_ed members take
priority over the members of the containing struct.
the comparison will only compare the kind of the type.
And ignore the typeIndex.
Which then means that every classType is considered equal to
every other classType.
Which will cause every class to refer to the same dynamic cast,
which is only generated for the first dynamic cast encountered.
The Moral of this, if you use any implicitly generated members,
stay away from alias this.
chances are minor changes to the contained type make it shadow
certain members that it did not shadow before, and in case of
auto-generated members you cannot even insert debug_prints to
ensure they are being called.
Before I noticed the bug I rewrote a lot of my low-level code
(because I thought my code-generation was at fault) introducing
even more bugs which I had to fix after I found the real culprit.
PS. my vacation is over so it will most likely grow silent around
Rest assured though that it is not dead and is being worked on!
It's just that my time-budget severely decreased.
See you at dconf!