[GSoC 2025] Templated Hooks - Weekly Update #1
AlbertG
albert.guiman at protonmail.com
Sun Jun 8 09:47:36 UTC 2025
This week I've finished the templatization of
[`_d_paint_cast`](https://github.com/dlang/dmd/pull/21427). 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:
```d
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`.
More information about the Digitalmars-d
mailing list