How to test for equality of types?

Matthias Walter xammy at xammy.homelinux.net
Sat May 19 11:17:08 PDT 2012


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


More information about the Digitalmars-d-learn mailing list