How to test for equality of types?

Kenji Hara k.hara.pg at gmail.com
Sun May 20 20:27:47 PDT 2012


On Sunday, 20 May 2012 at 06:57:20 UTC, Kenji Hara wrote:
> On Saturday, 19 May 2012 at 18:17:16 UTC, Matthias Walter wrote:
>> On 2012-05-19 15:28, Philippe Sigaud wrote:
>>> On Sat, May 19, 2012 at 12:23 PM, Matthias Walter
>>> <xammy at xammy.homelinux.net> wrote:
>>> 
>>>> I would open a bug report with the following code which is a 
>>>> bit smaller
>>>> than my first wrong version:
>>>>
>>>> =====================
>>> (...)
>>>> pragma(msg, typeof(w.aliasStruct).Alias.stringof); // -> 
>>>> "MyStruct"
>>>> pragma(msg, AliasStruct.Alias.stringof); // -> "MyStruct"
>>>> static assert(is(typeof(w.aliasStruct) == AliasStruct)); // 
>>>> -> true
>>>> static assert(is(typeof(w.aliasStruct).Alias == 
>>>> AliasStruct.Alias));
>>>> // -> false
>>>> }
>>> 
>>> Seems like a pb concerning whether Alias is a type or a 
>>> symbol. See
>>> A,B,C,D below:
>>> 
>>> void main()
>>> {
>>> Wrapper w;
>>> 
>>> pragma(msg, typeof(w.aliasStruct).Alias.stringof); // -> 
>>> "MyStruct"
>>> pragma(msg, AliasStruct.Alias.stringof); // -> "MyStruct"
>>> static assert(is(typeof(w.aliasStruct) == AliasStruct)); // 
>>> -> true
>>> static assert(is(w.aliasStruct.Alias == AliasStruct.Alias)); 
>>> // -> true
>>> 
>>> alias typeof(w.aliasStruct) A; // -> OK
>>> //alias typeof(w.aliasStruct).Alias B; // -> NOK
>>> //alias A.Alias C; // -> NOK
>>> alias w.aliasStruct.Alias D; // -> OK
>>> 
>>> static assert(is(A.Alias == AliasStruct.Alias)); // -> true
>>> //static assert(is(B == AliasStruct.Alias));
>>> //static assert(is(C == AliasStruct.Alias));
>>> static assert(is(D == AliasStruct.Alias)); // -> true
>>> }
>>> 
>>> I think A is enough for your need, but I don't get why B and 
>>> C are not
>>> accepted (DMD 2.059, Linux)
>>> 
>>
>> Using the current git version of dmd I realized that C works! 
>> Hence, as
>> a workaround it can be used by creating a local alias A and 
>> subsequently
>> using A.Alias in the is-expressions. But it seems odd that
>>
>> "alias typeof(X).A B;" does not work but
>> "alias typeof(X) Y; alias Y.A B;" does.
>>
>> Is this considered as a bug?
>>
>> Best regards,
>>
>> Matthias
>
> It seems to me that is a regression by fixing bug 6475.
> Now I'm trying to fix them.

Fixed in git head:
https://github.com/D-Programming-Language/dmd/commit/76543ef60f3b871612ddc0c87999859f427ba6f9


More information about the Digitalmars-d-learn mailing list