Thread overview
TypeFunction example: reason about class hierachies
Oct 24, 2020
Stefan Koch
Oct 24, 2020
Stefan Koch
Oct 24, 2020
Adam D. Ruppe
Oct 24, 2020
Stefan Koch
Oct 24, 2020
Adam D. Ruppe
Oct 24, 2020
Stefan Koch
Oct 24, 2020
Stefan Koch
October 24, 2020
Hi Folks,

Luckily no one uses type functions yet otherwise I would have to announce a breaking change.
The type of types changed it's name again from __type to __type__.

Since it turns out that the glibc in.h header uses __type as a parameter name already.
Let's hope no one is using __type__.
Because the only option I have after that is '__type___make_______bloody_sure____no_one_____uses_this____as_an_identifier'

The code below should be fairly self explanatory.

Please let me know what you think

---
alias type = __type__;
type getSuper(type T)
{
    return __traits(getSuper, T);
}

class B {}
class C : B{}
class D : B {}
bool eq(type A, type B)
{
    return is(A == B);
}

pragma(msg, getSuper(B).eq(getSuper(C)) ); // false
pragma(msg, getSuper(C).eq(B) ); // true
pragma(msg, getSuper(D).eq(getSuper(C)) ); // true
---

P.S. getting is(Myclass SuperType == super) to work, requires unreasonably much code.
Since I would need to extend my partial evaluation system ... let's not go into it.
I can explain it though if desired.
Besides ... the syntax is one of the things I always look up.
__traits(getSuper) should be more intuitive.

October 24, 2020
On Saturday, 24 October 2020 at 20:27:37 UTC, Stefan Koch wrote:
>
> Please let me know what you think
>

P.P.S
The compiler (from [https://github.com/UplinkCoder/dmd]) supports this starting with the git commit hash e46c6f5bb022aa3d1e7f3208f4b92bd0af9eceb5 onwards.

P.P.P.S

pragma(msg, getSuper(B)); // "Object"
pragma(msg, getSuper(B).getSuper()); // "__emptyType"
ragma(msg, getSuper(B).getSuper().getSuper()); // also "__emptyType"
October 24, 2020
On Saturday, 24 October 2020 at 20:27:37 UTC, Stefan Koch wrote:
> P.S. getting is(Myclass SuperType == super) to work, requires unreasonably much code.

Is the main blocker there that it only works to make the alias in static if?
October 24, 2020
On Saturday, 24 October 2020 at 20:54:45 UTC, Adam D. Ruppe wrote:
> On Saturday, 24 October 2020 at 20:27:37 UTC, Stefan Koch wrote:
>> P.S. getting is(Myclass SuperType == super) to work, requires unreasonably much code.
>
> Is the main blocker there that it only works to make the alias in static if?

The main blocker is that it that `SuperType` is Identifier, I would have to change the way Is Expressions are represented.
And inject a variable into the scope.
It's quite messy to do that.

October 24, 2020
On Saturday, 24 October 2020 at 21:01:19 UTC, Stefan Koch wrote:
> The main blocker is that it that `SuperType` is Identifier, I would have to change the way Is Expressions are represented.
> And inject a variable into the scope.

They already do that, so why can't you just use the existing code?
October 24, 2020
On Saturday, 24 October 2020 at 22:59:00 UTC, Adam D. Ruppe wrote:
> On Saturday, 24 October 2020 at 21:01:19 UTC, Stefan Koch wrote:
>> The main blocker is that it that `SuperType` is Identifier, I would have to change the way Is Expressions are represented.
>> And inject a variable into the scope.
>
> They already do that, so why can't you just use the existing code?

Because that only works when you have a new socpe.
I _could_ inject a fake variable but it's a really nasty thing to do, since it's an AST change.
I do not want to change the AST of the function.
Really not.
October 24, 2020
On Saturday, 24 October 2020 at 22:59:00 UTC, Adam D. Ruppe wrote:
> On Saturday, 24 October 2020 at 21:01:19 UTC, Stefan Koch wrote:
>> The main blocker is that it that `SuperType` is Identifier, I would have to change the way Is Expressions are represented.
>> And inject a variable into the scope.
>
> They already do that, so why can't you just use the existing code?

Also why would I support such un-intuitive syntax?
Are there any reasons other than backwards compatibility?