This week I've finished the templatization of _d_paint_cast
. In the process, I have also created a new template hook called _d_cast
that will be a wrapper meant to delegate the appropriate casting hook based on the provided template arguments. This way, all casts will be lowered to this single hook, making the code cleaner and more maintainable.
The only issue I encountered was a failing test caused by the use of std.typecons.Rebindable
. A slightly simplified code snippet that illustrates the problem is as follows:
class A {}
final class B : A {}
struct Reb(T, U)
{
private union
{
T original;
U stripped;
}
this(T initializer) pure nothrow @nogc
{
stripped = cast(U) initializer;
}
alias original this;
}
void main(){
Reb!(const(A), A) a = new B();
auto b = cast(const(B)) a;
assert(b !is null);
}
The issue stems from the use of alias this
, which caused the expression casted from to have the type struct Reb!(const(A), A)
, rather than the expected const(A)
. This was fixed by unaliasing the expression before performing the type checks in expressionsem.d
.