www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - is Expression, Type Identifier : TypeSpecialization

reply Andrej Mitrovic <andrej.mitrovich gmail.com> writes:
Hi,

On the expressions page,
http://www.digitalmars.com/d/2.0/expression.html

under section 5: "is ( Type Identifier : TypeSpecialization  )" it states:

"The condition is satisfied if Type is the same as TypeSpecialization, or if
Type is a class and TypeSpecialization is a base class or base interface of it.
The Identifier is declared to be either an alias of the TypeSpecialization or,
if TypeSpecialization is dependent on Identifier, the deduced type."

The following prints 'test':

    class one { }
    class two : one {  }
    
    alias one ONE;
    alias two TWO;
    
    static if ( is(TWO : ONE) )
        writeln("test");

But if I add an Identifier T, the 'is' expression evaluates to 0, writeln is
not executed:

    class one { }
    class two : one {  }
    
    alias one ONE;
    alias two TWO;
    
    static if ( is(TWO T : ONE) )
        writeln("test");

Is this a bug, or am I doing it wrong?
Jun 23 2010
next sibling parent reply Trass3r <un known.com> writes:
     class one { }
     class two : one {  }
    alias one ONE;
     alias two TWO;
    static if ( is(TWO T : ONE) )
         writeln("test");

 Is this a bug, or am I doing it wrong?

If it works without the aliases this is another strange alias bug.
Jun 24 2010
parent Andrej Mitrovic <andrej.mitrovich gmail.com> writes:
Trass3r Wrote:

     class one { }
     class two : one {  }
    alias one ONE;
     alias two TWO;
    static if ( is(TWO T : ONE) )
         writeln("test");

 Is this a bug, or am I doing it wrong?

If it works without the aliases this is another strange alias bug.

Do you mean the "alias one ONE; alias two TWO;" statements, or the missing T alias? In the first case, If I comment out the two alias statements, it will still compile. But that's not a bug, it's still syntactically correct (in that case "ONE" and "TWO" don't exist, but the compiler won't complain about it). In the second case, the aliased identifier doesn't need to be there unless we want to use it, see form #2 of the is expressions near the bottom of the page: http://www.digitalmars.com/d/2.0/expression.html
Jun 24 2010
prev sibling parent Trass3r <un known.com> writes:
You are right.

Even this doesn't work:

import std.stdio;

class one { }
class two : one {  }

void main()
{
	static if ( is(two T : one) )
		writeln("test");
}

Additionally it's really strange dmd doesn't complain about TWO and ONE if  
the aliases are omitted.
Seems like two distinct bugs to me.
File bug reports.
Jun 24 2010