[Bug 31] New: Keyword 'function' and pointer test broken for IsExpression

Sean Kelly sean at f4.ca
Wed Mar 15 11:06:47 PST 2006


Thomas Kuehne wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
> 
> d-bugmail at puremagic.com schrieb am 2006-03-10:
>> Given the documentation, I would expect all eight tests to pass, yet tests six
>> and eight both fail.
>>
>>
>> C:\code\d\bugs>type 149_1.d
>> import std.c.stdio;
>>
>> template isPointer( T )
>> {
>>     const bool isPointer = is( T : T* );
>> }
>>
>> void main()
>> {
>>     struct S {}
>>     union U {}
>>     class C {}
>>     interface I {}
>>     enum E { e }
>>     alias void function() fp;
>>     alias void delegate() dp;
>>
>>     static if( is( S == struct ) ) printf( "1. struct passes\n" );
>>     static if( is( U == union ) ) printf( "2. union passes\n" );
>>     static if( is( C == class ) ) printf( "3. class passes\n" );
>>     static if( is( I == interface ) ) printf( "4. interface passes\n" );
>>     static if( is( E == enum ) ) printf( "5. enum passes\n" );
>>     static if( is( fp == function ) ) printf( "6. function passes\n" );
>>     static if( is( dp == delegate ) ) printf( "7. delegate passes\n" );
>>     static if( isPointer!(int*) ) printf( "8. pointer passes\n" );
>> }
>> C:\code\d\bugs>dmd 149_1.d
>> C:\bin\dmd\bin\..\..\dm\bin\link.exe 149_1,,,user32+kernel32/noi;
>>
>> C:\code\d\bugs>149_1
>> 1. struct passes
>> 2. union passes
>> 3. class passes
>> 4. interface passes
>> 5. enum passes
>> 7. delegate passes
> 
> Shouldn't isPointer be defined as:
> 
> # template isPointer( T ){
> #     const bool isPointer = is( T : void* );
> # }
> 
> http://www.digitalmars.com/d/expression.html#IsExpression
> # is ( Type : TypeSpecialization )
> # The condition is satisfied if Type is semantically correct and it is
> # the same as or can be implicitly converted to TypeSpecialization.
> 
> Thus "is(T : T*)" is always false.

Good point.  However, this is inconsistent with the template 
specialization syntax, where "template foo( T : T* )" is completely 
valid.  But perhaps that doesn't matter as IsExpression differs in other 
ways as well.  I suppose that leaves 'function' then.

By the way, this code:

     class C { void fn() {} }
     static if( is( typeof(C.fn) == function ) )
         pragma( msg, "is function\n" );
     static if( is( typeof(C.fn) == delegate ) )
         pragma( msg, "is delegate\n" );


prints "is function" if compiled.  Aren't non-static class functions 
actually delegates?


Sean



More information about the Digitalmars-d-bugs mailing list